连接的第一个和最后一个元素

连接的第一个和最后一个元素

本文介绍了python27 matplotlib:连接的第一个和最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我发现了同样的问题,但没有答案:在此处输入链接描述

Hi I have found the same problem but without an answer:enter link description here

我的问题是我尝试使用matplotlib绘制数据并将其连接到第一个和最后一个数据点.我正在使用python27和Windows7.我的问题只是显示完整而已,所以我仅显示源代码的某些部分.绘图功能如下:

My problem is that I try to plot data with the matplotlib and it connects the first and the last data point. I am using python27 and Windows 7. My problem is just to big to show complete so I just show some parts of the source code. The plot function is as below:

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中,有时想刷新它.情节看起来像:

I am using this, because I am plotting this in a Tkinter Gui and want to refresh it sometimes. The plot looks like:

我的价值观是:

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

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

Is it a problem that I do not start with zero in the t array?

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

If anybody has a hint or knows the problem please help me.

欢呼声最高

推荐答案

好问题!从圆形缓冲区绘制时间戳数据时遇到了类似的问题.其他答案解释了发生了什么.

Good question!Had a similar problem while plotting time stamped data from a circular buffer. The other answers explained what was going on.

该图按严格顺序处理矢量,在第一个坐标到第二个坐标之间画一条线,依此类推.但是循环缓冲区可以在任何时候以最短的时间开始.

The plot is processing the vectors in strict order, drawing a line from first coordinate to second and so on. But a circular buffer can start with lowest time at any point.

因此,绘图通常会在绘图窗口中间的某个位置以良好的增量时间开始.然后它到达插入点并及时 back 跳到窗口的起点-画一条难看的线-然后恢复到起点.

Thus the plot will often start somewhere in the middle of the plot window with nice incrementing time. Then it reaches the insertion point and jumps back in time to the start of the window -- drawing an ugly line -- then resuming up to the starting point.

快速的解决方案是替换此行:

The quick solution was replacing this line:

plot(pTime, pPos)

有两条线以正确的顺序绘制每半:

with two lines plotting each half in the right order:

plot(pTime[ptr:], pPos[ptr:])
plot(pTime[0:ptr], pPos[0:ptr])

这篇关于python27 matplotlib:连接的第一个和最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:13