2

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 ?

3
  • what do you expect? Commented Dec 6, 2020 at 7:07
  • images added. you can see now Commented Dec 6, 2020 at 7:13
  • @py_kumar maybe upgrade your matplotlib to latest version. I'm not getting scientific notation. Commented Dec 6, 2020 at 8:21

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Why this was downvoted ? Using plot makes the graph looks clearer than axis
I didn't downvote but I guess someone saw this answer as similar to mine that's why.
@Pygirl its similar , but using axis makes the graph looks thicker , ploot makes it look more cleaner
If the question is answered through other answer then suggestion related to improvement can be made to other answer via comment :)
Sure will do that
0

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

2 Comments

working now, is this required in every code ?
plt is used for a current plot so I guess yes but I think there will be a way to make it for everyplot without reusing the same.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.