python27 matplotlib : first and last element connected

标签 python matplotlib plot

您好,我发现了同样的问题,但没有答案: enter link description here

我的问题是我尝试使用 matplotlib 绘制数据,它连接了第一个和最后一个数据点。我使用的是 python27 和 Windows 7。我的问题太大了,无法显示完整,所以我只显示了部分源代码。绘图函数如下:

def plot(x, aw,temperature):
    plt.clf()
    temperatureplot = plt.subplot(211)
    awplot = plt.subplot(212)

    temperatureplot.grid()
    awplot.grid()  

    #set subplots
    awplot.set_ylabel('water activity aw')
    awplot.plot(x,aw)
    awplot.margins(y=0.05) #adds a gap between maximum value and edge of diagram
    temperatureplot.set_ylabel('Temperature in degree C')
    temperatureplot.plot(x,temperature)
    temperatureplot.margins(y=0.05)

    awplot.set_xlabel('Time in [hm]')
    plt.gcf().canvas.draw()

我正在使用它,因为我在 Tkinter Gui 中绘制它并且有时想刷新它。情节看起来像: enter image description here

我的值(value)观是:

t = [161000, 161015...., 191115]
aw = [0.618,......, 0.532]
temperature = [23.7,....,24.4]

我在 t 数组中不从零开始是个问题吗?

如果有人有提示或知道问题所在,请帮助我。

干杯麦克斯

最佳答案

Pyplot 正在连接第一个 (x,y) 点和第二个 (x,y) 点,然后是第三个点,依此类推...所以看起来可能有一个(重复的?)低值隐藏在x 结束。

您可以尝试 x == sorted(x) 来仔细检查您的列表是否严格按升序排列。如果不是,它将返回 False

在调用 plot() 函数之前,您可能希望找到 (x,y) 对,所以我现在将其留给您。

关于python27 matplotlib : first and last element connected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28016764/

相关文章:

python - 是否可以有多个 PyPlot 窗口?还是我仅限于子图?

python - Flask:如何管理不同环境的数据库?

python - 如何使用 ffmpeg 在 python 中检查视频损坏?

python - 2D 传热 - 溢出错误

r - 轴标签中的数学表达式

r - 使用颜色作为第三维度

python - Dask agg函数 pickle 错误

python - 如何使用 Python 在一组点上绘制多边形(部分向内弯曲)边缘?

python - python中的堆叠条偏移

python - Matplotlib timedelta64 索引作为 x 轴