not getting expected result in matplotlib python

Viewed 58

not getting expected values in y axis ,is there any problem in my code ? plot i m getting, plot expected

import matplotlib.pyplot as plt
x_values = list(range(1,1001))

y_values = [ x**2 for x in x_values]
plt.scatter(x_values,y_values,s=40)

plt.title("scattered squares 2",fontsize=15)
plt.xlabel("value",fontsize=14)
plt.ylabel("square of value",fontsize=15)
# Set the range for each axis.
plt.axis([0,1100,0,1100000])
plt.show()

not getting expected values in y axis ,is there any problem in my code ?

2 Answers

using plot is much cleanrer :

import matplotlib.pyplot as plt
x_values = list(range(1,1001))

y_values = [ x**2 for x in x_values]

plt.ticklabel_format(style='plain') #< ---- here
plt.title("scattered squares 2",fontsize=15)
plt.xlabel("value",fontsize=14)
plt.ylabel("square of value",fontsize=15)
# Set the range for each axis.
plt.plot(x_values,y_values)
plt.show()

Output:

enter image description here

Use plt.ticklabel_format(style='plain') to disable scientific notation.

import matplotlib.pyplot as plt
x_values = list(range(1,1001))

y_values = [ x**2 for x in x_values]
plt.scatter(x_values,y_values,s=40)
plt.ticklabel_format(style='plain') #< ---- here
plt.title("scattered squares 2",fontsize=15)
plt.xlabel("value",fontsize=14)
plt.ylabel("square of value",fontsize=15)
# Set the range for each axis.
plt.axis([0,1100,0,1100000])

plt.show()

enter image description here

Related