Skip to content Skip to sidebar Skip to footer

Why Doesn't Adjusting Scilimits In Matplotlib Work Properly?

I am trying to make a plot with the same scilimits using the following code: from matplotlib import rc rc('text', usetex=True) plt.rcParams['text.latex.preamble']=[r'\usepackage{am

Solution 1:

The following solution is based on a similar post by the matplotlib wizard ImportanceOfBeingErnest ;)

Here you just apply the modification to the x-axis since the y-axis values are already below 10^6.

Please upvote the original post on the above link if you find it helpful.

from matplotlib import rc
import matplotlib.ticker 

fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111)

# Your data hereclassOOMFormatter(matplotlib.ticker.ScalarFormatter):
    def__init__(self, order=0, fformat="%1.1f", offset=True, 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$' % matplotlib.ticker._mathdefault(self.format)


plt.plot(bbbb, aaaa, 'k*', label="$A$", markerfacecolor='none', markersize = 8)

plt.ticklabel_format(style='sci', axis='y', scilimits=(5,5), useMathText=True)

# Setting the x-axis notation as 10^5
ax.xaxis.set_major_formatter(OOMFormatter(5, "%1.1f"))
ax.ticklabel_format(axis='x', style='sci', scilimits=(5,5))

# Remaining code here

enter image description here

Post a Comment for "Why Doesn't Adjusting Scilimits In Matplotlib Work Properly?"