[Matplotlib-users] Some beginner questions
David Aldrich
David.Aldrich at EMEA.NEC.COM
Fri Nov 13 07:52:19 EST 2015
Hi
I'm new to Matplotlib and am struggling a bit.
I'm using Matplotlib with the Kivy GUI framework, but that shouldn't be directly relevant. I want to show a single figure having 4 subplots, each displaying one line. My code looks like this (simplified):
class CMplGraph():
pass
def __init__(self, **kwargs):
self.create_plot()
def create_plot(self):
self.fig, ((self.ax0, self.ax1), (self.ax2, self.ax3)) = plt.subplots(nrows=2, ncols=2)
self.ax0.set_title("Title_0")
self.ax1.set_title("Title_1")
self.ax2.set_title("Title_2")
self.ax3.set_title("Title_3")
plt.show()
def plot(self, plotType, xCoords, yCoords):
if (plotType == "PLOT_0 "):
ax = self.ax0
elif (plotType == " PLOT_1"):
ax = self.ax1
elif (plotType == " PLOT_2"):
ax = self.ax2
elif (plotType == " PLOT_3"):
ax = self.ax3
else:
raise BadPlotType(plotType)
# remove previous line
if len(ax.lines) > 0:
ax.lines.pop(0)
plt.draw()
time.sleep(1) # Blink
line = ax.plot(xCoords, yCoords, color='blue')
canvas = self.fig.canvas
canvas.draw()
Then my main app can call create_plot() once, followed by plot() whenever it wants to update the displayed data.
This seems to work but I'm not sure I'm doing it correctly. Here are my questions:
1) Is it ok that I created axis objects?
2) Am I removing the previous line correctly?
3) I would like display to 'blink' between successive calls to plot(). So I put in a 1s sleep after removing the previous line. There should therefore be a flash before the new data is displayed. But I don't see that blink - the line updates instantaneously. Why is that?
Best regards
David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151113/6eaf95e0/attachment-0001.html>
More information about the Matplotlib-users
mailing list