简体   繁体   中英

Why would plot() for Matplotlib plot different values from those passed in?

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): 清单内容

The following is the graphical output: 坏图

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: 其他清单内容 好图

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM