简体   繁体   English

在pyplot中绘制大曲线后绘制负到正范围

[英]Plotting negative-to-positive range after plotting large curve in pyplot

Using Python 2 open a console and type: 使用Python 2打开控制台并键入:

from matplotlib import pyplot as plt
plt.ion()
plt.plot([2457100+i for i in range(1,100,10)],[i for i in range(1,100,10)])
plt.cla()
plt.plot([-40,-20,-0,20,40],[10,2,5,4,5])

The first plot will add a +2.4571e6 to the axis to make notation easier. 第一个绘图将在轴上添加+ 2.4571e6以使表示法更容易。 Oddly enough, once clearing and plotting the second curve, the axis will remain with this shifting, such that the data is properly labeled but at incredibly negative numbers (-2457140...)! 奇怪的是,一旦清除并绘制了第二条曲线,该轴便会保持这种偏移,从而正确标记了数据,但其负数令人难以置信(-2457140 ...)!

This isn't reproducible if the second plot has a positive range. 如果第二个图的范围是正数,则无法重现。 My current workaround is to cla() and re-plot the sample plot again, as after another cla() the axis becomes normal. 我当前的解决方法是cla()并再次重新绘制样本图,因为在另一个cla() ,轴变为法线。 This may become too costly for me (time wise), so I'm looking for other workarounds, and to make sure it is a bug. 这对我来说可能太昂贵(按时),因此我正在寻找其他解决方法,并确保它是一个错误。 clf() isn't an option unfortunately, I need to retain the axes. 不幸的是, clf()不是一个选项,我需要保留轴。

Running your code in IPython 5 with matplotlib 2.0 I cannot reproduce the issue. 在带有matplotlib 2.0的IPython 5中运行代码,我无法重现该问题。 The second plot has the correct scale after a single call to plt.cla() . 在单次调用plt.cla()之后,第二个图具有正确的比例。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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