Python Matplotlib在Raspberry pi中没有显示一行,但在Ubuntu中显示

Python Matplotlib在Raspberry pi中没有显示一行,但在Ubuntu中显示,python,matplotlib,Python,Matplotlib,我有一个脚本,它在Ubuntu 16.04中运行得很好,但在Raspbian中却没有 我正在绘制这些数据(datosPlot.txt): 第一列是日期和时间,第二列是pH值,第三列是温度 在raspbian中,脚本仅绘制第三列(温度)和日期/时间(第一列),比例正确 这是我的代码: import matplotlib.pyplot as plt import matplotlib.dates as mdates from datetime import datetime import numpy

我有一个脚本,它在Ubuntu 16.04中运行得很好,但在Raspbian中却没有

我正在绘制这些数据(
datosPlot.txt
):

第一列是日期和时间,第二列是pH值,第三列是温度

在raspbian中,脚本仅绘制第三列(温度)和日期/时间(第一列),比例正确

这是我的代码:

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime
import numpy as np    
import matplotlib.animation as animation

datefunc = lambda x: mdates.date2num(datetime.strptime(x, '%d-%m-%Y_%H:%M:%S'))
def animate(i):
    dates, ph, temp = np.genfromtxt('datosPlot.txt', converters={0: datefunc}, usecols=(0,1,2), invalid_raise=False, unpack=True)
    ax1.clear()
    ax2.clear()
    ax1.grid(True)
    ax2.grid(True)

    ax1.plot_date(dates, ph, ls='-', marker='.', color='red', label='pH')
    ax1.set_ylabel('pH')
    ax2.plot_date(dates, temp, ls='-', marker='.', color='blue', label='Temperatura C')
    ax2.set_ylabel('Temperatura C')

    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M'))
    lines = ax1.get_lines() + ax2.get_lines()
    plt.legend(lines, [l.get_label() for l in lines], loc=2)
    fig.tight_layout()
fig = plt.figure()
fig.canvas.set_window_title('Grafica pH y Temperatura')
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx() 
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show() 

有趣的是,它确实读取了第二列(pH),因为图表显示的是正确的比例,而不是直线。另外,如果我在最后几行中更改
ax1
ax2
ax1=fig.add_sublot(111)
ax2=ax1.twin()
),我会绘制pH值,但不会绘制温度。

你能在问题中贴出你使用的mpl版本吗?这是胡乱猜测,但Rasbian上使用的后端matplotlib可能与Ubuntu上的不同。如果绘制到后端系统时出现问题,则不会绘制线条。但这不应该发生。不是在最疯狂的梦里。不过还是要检查一下。matplotlib.get_backend()。如果不一样,请在Rasbian上安装Ubuntu上的一个,然后试着用它画画。谢谢你,不幸的是,我要到明天才能尝试。我将update@Lucas问题在于mpl的不同版本。现在两者都是
1.5.1
,并且工作正常(使用python3)。非常感谢。
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime
import numpy as np    
import matplotlib.animation as animation

datefunc = lambda x: mdates.date2num(datetime.strptime(x, '%d-%m-%Y_%H:%M:%S'))
def animate(i):
    dates, ph, temp = np.genfromtxt('datosPlot.txt', converters={0: datefunc}, usecols=(0,1,2), invalid_raise=False, unpack=True)
    ax1.clear()
    ax2.clear()
    ax1.grid(True)
    ax2.grid(True)

    ax1.plot_date(dates, ph, ls='-', marker='.', color='red', label='pH')
    ax1.set_ylabel('pH')
    ax2.plot_date(dates, temp, ls='-', marker='.', color='blue', label='Temperatura C')
    ax2.set_ylabel('Temperatura C')

    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y %H:%M'))
    lines = ax1.get_lines() + ax2.get_lines()
    plt.legend(lines, [l.get_label() for l in lines], loc=2)
    fig.tight_layout()
fig = plt.figure()
fig.canvas.set_window_title('Grafica pH y Temperatura')
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx() 
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()