1

I am plotting the graph in python. I want to roundoff the y-axis as the values are too larger

I tried this code

df = pd.read_csv("data.csv", delimiter=",")
plt.plot(df['No'], df['B'], marker='.',  color = 'green')
#plt.plot(df['No'], df['B'], marker='.', label='bb')
#plt.show()
plt.xlabel('No')
plt.ylabel('B')
plt.xticks(np.arange(1, 10+1, 2))
plt.grid()
plt.show()

my graph looks like this enter image description here

how can I round off the y-axis

user12
  • 761
  • 8
  • 24
  • what exactly do you mean by "round off"? Do you want to use scientific notation, e.g., 2e5 or do you want to limit the maximum y-values? – BanDoP Mar 29 '22 at 11:54
  • @BanDoP exactly – user12 Mar 29 '22 at 11:55
  • Does this answer your question? [prevent scientific notation in matplotlib.pyplot](https://stackoverflow.com/questions/28371674/prevent-scientific-notation-in-matplotlib-pyplot) – Mr. T Mar 29 '22 at 12:02

1 Answers1

0

Well, limiting the y-axis is done by plt.ylim(0, 500000) while changing the format can be done by this snippet, that I copied from somewhere some time ago:

from matplotlib.ticker import ScalarFormatter

formatter1 = ScalarFormatter(useOffset=True)  
formatter1.set_powerlimits((-3, 3))  #  use scientific notation below 10^-3 and above 10^3
ax.yaxis.set_major_formatter(formatter1)
BanDoP
  • 79
  • 5