0

I have some Python code (running on Python3) for Matplotlib that boils down to the following:

title = 'A title'
fig, ax = plt.subplots()
x_values = []  
y_values = []  
# x_values and y_values are populated by extracting values from a dict I pass in.
# The values are extracted correctly; I printed them out for a sanity check.

plt.plot(x_values, y_values)

ax.set_xlim([0, 100])
plt.ylabel('Y')
plt.xlabel('X')
plt.title(title, fontsize=title_size)
fig.autofmt_xdate()

plt.show()

The following shows what is in x_values and y_values for a particular dict (it so happens all the y values are the same for this particular dataset): List contents

The following is the graphical output: Bad graph

Note that not only is the graph shape is unexpected, but the y-axis scale is incredibly off as well.

I cannot fathom why this is happening. For other datasets with more variation, I get better graphs where the plotted values match my raw values. For example: Other list contents Good graph

Is there some oddity of plot() I am unaware of? Or am I using a bad sequence or combination of code? Otherwise, what could cause this?

3
  • Please don't post pictures of code or data - share the data with us ( a minimal example). Commented Sep 9, 2017 at 5:07
  • 3
    It is printing the numbers you are showing - but the axis is only displaying the significant digits, i.e. the 6 and 7 decimal places Commented Sep 9, 2017 at 5:14
  • Wow this was a horrible question... I didn't imagine the autoscaling would be so unintelligent so I didn't check the numbers carefully! Commented Sep 9, 2017 at 5:47

1 Answer 1

2

The plot is autoscaled. Vaues in your first plot are in a small range. If you look on top left of your plot, there is a number 1e-7+2.44005249e2 meaning that all values on y must be read as value_on_y*1e-7 + 244.005249, in other words, the number on y axis are only 6th and 7th digits after delimiter in your data.

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

Comments