python - Factors and shifts in offsets for matplotlib axes labels -


on axes tick labels in matplotlib, there 2 kinds of possible offsets: factors , shifts:

enter image description here

in lower right corner 1e-8 "factor" , 1.441249698e1 "shift".

there lot of answers here showing how manipulate both of them:

i remove shifts , can't seem figure out how it. matplotlib should allowed scale axis, not move 0 point. is there simple way achieve behaviour?

you can fix order of magnitude show on axis shown in this question. idea subclass usual scalarformatter , fix order of magnitude show. setting useoffset false prevent showing offset, still shows factor.

thwe format "%1.1f" show 1 decimal place. using maxnlocator allows set maximum number of ticks on axes.

import numpy np import matplotlib.pyplot plt import matplotlib.ticker  class oomformatter(matplotlib.ticker.scalarformatter):     def __init__(self, order=0, fformat="%1.1f", offset=false, mathtext=true):         self.oom = order         self.fformat = fformat         matplotlib.ticker.scalarformatter.__init__(self,useoffset=offset,usemathtext=mathtext)     def _set_orderofmagnitude(self, nothing):         self.orderofmagnitude = self.oom     def _set_format(self, vmin, vmax):         self.format = self.fformat         if self._usemathtext:             self.format = '$%s$' % self.format  x = [0.6e-8+14.41249698, 3.4e-8+14.41249698] y = [-7.7e-11-1.110934954e-2, -0.8e-11-1.110934954e-2]  fig, ax = plt.subplots() ax.plot(x,y)  y_formatter = oomformatter(-2, "%1.1f") ax.yaxis.set_major_formatter(y_formatter) x_formatter = oomformatter(1, "%1.1f") ax.xaxis.set_major_formatter(x_formatter)  ax.xaxis.set_major_locator(matplotlib.ticker.maxnlocator(2)) ax.yaxis.set_major_locator(matplotlib.ticker.maxnlocator(2))  plt.show() 

enter image description here

keep in mind plot inaccurate , shouldn't use in kind of report hand other people wouldn't know how interprete it.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -