Python 2.7 试图在我的python图表中显示标题

Python 2.7 试图在我的python图表中显示标题,python-2.7,matplotlib,arduino-uno,Python 2.7,Matplotlib,Arduino Uno,我正在用python和Arduino UNO制作示波器。我有两个奇怪的问题。首先,我想强调我的代码是有效的,但我想理解为什么会出现这些问题 首先,如果我尝试为我的人物命名,我的代码将停止工作。我已经发表了评论,并以三个问号结束了相关的三行 见代码: 我的第二个问题是为什么按钮不是彩色的(它们都是黑色的)并且不能点击。看 fig=plt.figure()。您想要的是有一个单独的图形,所以将fig=plt.figure()放在循环之外 由于这仍然会在彼此的顶部绘制许多线,因此更好的选择是更新这些线

我正在用python和Arduino UNO制作示波器。我有两个奇怪的问题。首先,我想强调我的代码是有效的,但我想理解为什么会出现这些问题

首先,如果我尝试为我的人物命名,我的代码将停止工作。我已经发表了评论,并以三个问号结束了相关的三行

见代码: 我的第二个问题是为什么按钮不是彩色的(它们都是黑色的)并且不能点击。看

fig=plt.figure()。您想要的是有一个单独的图形,所以将
fig=plt.figure()
放在循环之外

由于这仍然会在彼此的顶部绘制许多线,因此更好的选择是更新这些线

import serial
import numpy as np
import matplotlib.pyplot as plt

voltsent = [] #le signal reçu en chaine de caractères
signalsentfloat = [] #le signal reçu converti en float
ser = serial.Serial("com9",115200)
#affichage interactive des données
plt.ion()
cnt = 0

fig = plt.figure()
fig.suptitle(u'Visualisation de signaux générés par le GBF')

ax = plt.subplot(2,1,1)
ax.grid(True)
ax.set_ylabel('Signal')
line1, = ax.plot([],".")

ax2 = plt.subplot(2,1,2)
ax2.grid(True)
ax2.set_ylabel('Fourrier Transform')
line2, = ax2.plot([],"-")

def figuresignal(): #fonction qui affiche le siganl analogue
    line1.set_data(np.arange(len(voltsent)),voltsent )    
    line2.set_data(np.arange(len(voltsentFT)),voltsentFT )

while True: #while loop that loops forever
    while(ser.inWaiting()==0) :#wait here until there is a data
        pass
    signalsent = ser.readline() #read line of text from serial port
    signalsentfloat = float(signalsent) #convert it
    voltsent.append(signalsentfloat) #append its values to array
    voltsentFT = np.fft.fft(voltsent)
    figuresignal()
    plt.pause(.001)
    cnt = cnt+1
    if(cnt>50):
        voltsent.pop(0)

我已经找到了解决上述问题的方法,方法是遵循

为了给我的图表命名,我使用了函数:plt.title('Le titre ici')

你什么意思?他们不是一直都是黑人吗?您可以使用
plt.title(“我的图形”)
设置标题。您知道,我的图左下角的这些图标。我在Internet上看到一些绘图,它们的图标)是彩色的。我尝试了您所说的,但仍然不起作用。我很确定问题出在“suptitle”的名称中,但我不知道为什么。如果我将该行注释掉,问题就消失了。您能更准确地说什么不起作用吗?当我删除“suptitle line”中的注释符号时,图形不会出现在图形窗口中。谢谢您的回答。您是在谈论此答案中的代码吗?不管你是否在情节中加入超级标题。是的,我指的是上面的帖子。我知道这不重要,但我想知道为什么。再次感谢您的回复。
import serial
import numpy as np
import matplotlib.pyplot as plt

voltsent = [] #le signal reçu en chaine de caractères
signalsentfloat = [] #le signal reçu converti en float
ser = serial.Serial("com9",115200)
#affichage interactive des données
plt.ion()
cnt = 0

fig = plt.figure()
fig.suptitle(u'Visualisation de signaux générés par le GBF')

ax = plt.subplot(2,1,1)
ax.grid(True)
ax.set_ylabel('Signal')
line1, = ax.plot([],".")

ax2 = plt.subplot(2,1,2)
ax2.grid(True)
ax2.set_ylabel('Fourrier Transform')
line2, = ax2.plot([],"-")

def figuresignal(): #fonction qui affiche le siganl analogue
    line1.set_data(np.arange(len(voltsent)),voltsent )    
    line2.set_data(np.arange(len(voltsentFT)),voltsentFT )

while True: #while loop that loops forever
    while(ser.inWaiting()==0) :#wait here until there is a data
        pass
    signalsent = ser.readline() #read line of text from serial port
    signalsentfloat = float(signalsent) #convert it
    voltsent.append(signalsentfloat) #append its values to array
    voltsentFT = np.fft.fft(voltsent)
    figuresignal()
    plt.pause(.001)
    cnt = cnt+1
    if(cnt>50):
        voltsent.pop(0)