0

I am trying to plot a dataset with some really small values on xaxis. I want to use scientific notation for all numbers on Xaxis. So I tried

plt.ticklabel_format(style='sci', axis='x', scilimits=(0,0))

I get following errors:

xis.major.formatter.set_scientific(is_sci_style)
AttributeError: 'FuncFormatter' object has no attribute 'set_scientific'

can someone help me with that thank you very much.

my plot:

enter image description here

Ruvee
  • 8,611
  • 4
  • 18
  • 44

1 Answers1

-1

To apply scientific notation you can employ a formatter function. See this post: Can I turn of scientific notation in matplotlib bar chart?. I have applied the same logic as the user in the reference I have quoted to obtain the following simple example of a plot of a sine function with scientific notation on both axes.

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import FuncFormatter

x = np.linspace(0,100,1000)
y = np.sin(x)

def scientific(x, pos):
    # x:  tick value
    # pos: tick position
    return '%.2E' % x

# create figure
plt.figure()
# plot sine
plt.plot(x,y)
# get current axes 
ax = plt.gca()
# initialize formatter
scientific_formatter = FuncFormatter(scientific)
# apply formatter on x and y axes
ax.xaxis.set_major_formatter(scientific_formatter)
ax.yaxis.set_major_formatter(scientific_formatter)
# show plot
plt.show()
boxhot
  • 189
  • 5