SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S

1
(2)
2
(32)
3
(26)
4
(29)
5
(41)
6
(2)
7
(1)
8
(13)
9
(15)
10
(23)
11
(23)
12
(16)
13
(6)
14
(15)
15
(4)
16
(18)
17
(28)
18
(17)
19
(11)
20
(6)
21
(2)
22
(4)
23
(1)
24
25
26
(1)
27
(2)
28
(2)
29
(3)
30
(10)
31
(2)



Showing 4 results of 4

From: troyrock <tro...@ro...> - 2012年10月22日 23:22:25
I figured out the problem. I need to call self.canvas.draw() in order to
update the image. Sorry for the email.
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Would-like-to-update-visible-plot-using-pyside-and-matplotlib-tp39576p39577.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: troyrock <tro...@ro...> - 2012年10月22日 23:04:27
I have a tool to show information extracted from various experiments and then
stored in a database. I would like to update a plot shown in the lower half
of the window when information such as the ranges of variables are modified
in the upper half. I can initially put data into the plot, however when I
want to change the contents (such as add another line to the plot), the 
changes don't get displayed. Here is some code to illustrate the problem:
import matplotlib
matplotlib.rcParams['backend.qt4'] = 'PySide'
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
matplotlib.use('Qt4Agg')
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as
FigureCanvas
from PySide import QtCore, QtGui
import sys
class TabDialog(QtGui.QDialog):
 def __init__(self):
 super(TabDialog, self).__init__()
 tabWidget = QtGui.QTabWidget()
 tabWidget.addTab(AnalyzeTab(), self.tr("Analyze"))
 buttonLayout = QtGui.QHBoxLayout()
 saveButton = QtGui.QPushButton(self.tr("Update"))
 saveButton.clicked[bool].connect(self.update)
 buttonLayout.addWidget(saveButton)
 mainLayout = QtGui.QVBoxLayout()
 mainLayout.addWidget(tabWidget)
 mainLayout.addLayout(buttonLayout)
 self.setLayout(mainLayout)
 def update(self):
 data.update()
class DataHolder():
 def __init__(self):
 self.gFig = Figure()
 self.ax = self.gFig.add_subplot(111)
 self.ax.plot([1,2,4,0.1])
 self.canvas = FigureCanvas(self.gFig)
 def update(self):
 self.ax.plot([8,6,4,2])
class AnalyzeTab(QtGui.QWidget):
 def __init__(self, parent=None):
 QtGui.QWidget.__init__(self, parent)
 analyzeLayout = QtGui.QGridLayout()
 analyzeLayout.addWidget(data.canvas, 2, 0, 6, 8)
 self.setLayout(analyzeLayout)
if __name__ == "__main__":
 app = QtGui.QApplication(sys.argv)
 data = DataHolder()
 tabdialog = TabDialog()
 tabdialog.show()
 sys.exit(app.exec_())
Any suggestions are very much appreciated.
--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Would-like-to-update-visible-plot-using-pyside-and-matplotlib-tp39576.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: fiolj <fi...@ya...> - 2012年10月22日 17:00:55
Hi, some time ago I needed the same thing and hacked the function
histogram (from numpy or matplo. Here goes my function
## Calculates the histogram allowing for overlapping bins, which are
given by
#
# @param a
# @param bins a sequence of pairs (left,right), limits for each bin
#
# @return hist (numpy array)
# bin_centers (numpy array)
def myhistogram(a, bins):
 """
 Compute the histogram of a set of data.
 Parameters
 ----------
 a : array_like
 Input data.
 bins : sequence of pairs
 It defines the bin edges (left,right), allowing for non-uniform
bin widths.
 Returns
 -------
 hist : array
 The values of the histogram. See `normed` and `weights` for a
 description of the possible semantics.
 bin_centers : array of dtype float
 Return the bin centers ``(length(hist))``.
 Notes
 -----
 All but the last (righthand-most) bin is half-open. In other words, if
 `bins` is::
 [1, 2, 3, 4]
 then the first bin is ``[1, 2)`` (including 1, but excluding 2) and the
 second ``[2, 3)``. The last bin, however, is ``[3, 4]``, which *includes*
 4.
 Examples
 --------
 >>> myhistogram([1,2,1], bins=[(0,1),(1,1.5),(1.5,2.5),(2,3)])
 (array([0.5, 1.25, 2, 2.5]), array([0, 0, 1, 2, 3]))
 """
 bins = np.asarray(bins) # bins are 2-dimensional arrays
of shape (n,2)
 if len(bins.shape) != 2 or bins.shape[1] != 2:
 raise AttributeError, 'bins must be a list/array of 2-tuples.'
 a = np.asarray(a)
 a = a.ravel()
 n = np.zeros(len(bins), int)
 block = 65536
 for i in np.arange(0, len(a), block):
 sa = np.sort(a[i:i+block])
 n += np.r_[sa.searchsorted(bins[:-1,1], 'left'),
sa.searchsorted(bins[-1,1], 'right')]\
 - np.r_[sa.searchsorted(bins[:-1,0], 'left'),
sa.searchsorted(bins[-1,0], 'right')]
 return n, (bins[:,0]+bins[:,1])/2.
From: Larry C. <lar...@gm...> - 2012年10月22日 15:55:36
Hi
I have been doing some work that generates a lot of plots and since the
plots were taking a long time I looked into to whether I could speed up the
process.
I found some information on how I might improve things from the following
link:
http://stackoverflow.com/questions/11688318/how-to-speed-up-matplotlib-when-plotting-and-saving-lots-of-figureswhich
showa that you can speed things up by using the same axes and simply
updating the line data.
When I adapted this idea to my plots I noticed that, though the plot loop
was quicker my script was running slower. I wrote a code snippet to repeat
the problem - shown below:
#!/usr/bin/env python
import os, matplotlib, time
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
from cmpactionresultsbetweenviews_1 import getPlotHtml
allActionPlotLists = [[0, 1, 2 , 3, 4, 5, 6, 7, 8, 9],
 [ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
 [9,8,7,6,5,4,3,2,1,0],
 [19,18,17,16,15,14,13,12,11,10]]
allActionLegendsLists = [str(i) for i in range(len(allActionPlotLists[0]))]
legendProps={'labelspacing':0.5, 'prop':{'size':8}}
colours=['b+-', 'r+-', 'g+-', 'k+-', 'c+-', 'm+-', 'bD:', 'rD:', 'gD:',
'kD:']
fig = plt.figure()
ax = None
plotlines = [None for i in range(len(allActionPlotLists))]
savedir = "tmpRes"
if not os.path.exists(savedir):
 os.makedirs(savedir)
figSrcFnRoot = "plotFil"
fil = open(os.path.join(savedir, "savepng.html"), 'w')
xlabel = "x label"
ylabel = "values"
colours=['b+-', 'r+-', 'g+-', 'k+-', 'c+-', 'm+-', 'bD:', 'rD:', 'gD:',
'kD:']
for i in range(20):
 start_plot_time = time.time()
 plottitle = "Plot %d" % (i)
 fig.suptitle("")
 fig.suptitle(plottitle)
 for subPltIdx in range(len(allActionPlotLists)):
 li = allActionPlotLists[subPltIdx]
 if ax == None:
 ax = fig.add_subplot(1,1,1)
 ax.set_xlabel(xlabel)
 ax.set_ylabel(ylabel)
 if plotlines[subPltIdx] == None:
 ax.set_xlabel(xlabel)
 ax.set_ylabel(ylabel)
 plotlines[subPltIdx] = ax.plot(range(len(li)), li,
colours[subPltIdx])[0]
 else:
 plotlines[subPltIdx].set_ydata(li)
 plotlines[subPltIdx].set_xdata(range(len(li)))
 fig.legend(plotlines, allActionLegendsLists, labelspacing=0.5,
prop=legendProps['prop'])
 # **** change the above line for the one below and the increasing save
time problem goes away
 #ax.legend(plotlines, allActionLegendsLists, labelspacing=0.5,
prop=legendProps['prop'])
 print "plot Execution time:", time.time()-start_plot_time
 figfn = "%s_%d" % (figSrcFnRoot, i)
 figfnlink = figfn.replace('%',
'%25').replace(';','%3b').replace(':','%3A')
 fn = os.path.join(savedir, "%s.png" % figfn)
 start_time = time.time()
 fig.savefig(fn, format='png',dpi=75)
 print "savefig Execution time:", time.time()-start_time
 htmlStr = ''
 htmlStr += '<center><img src="%s" alt="could not find %s
image"/></center>' % (os.path.join(".","%s.png" % figfnlink), figfn)
 fil.write(htmlStr + "<br>")
plt.close()
fil.close()
A little further investigation showed that savefig was taking longer each
run of the loop. I eventually noticed that replacing the call to
fig.legend() with ax.legend() solved the problem. Anyone know why the time
taken to save the plot increases when using fig.legend() in the code above ?
While doing this I also noticed a couple of other things:
1. I cannot seem to clear the figure title, so when I re-set it I get the
new title overlaying the old one in the plot output. Does anyone know how
to completely clear and reset the title of an existing figure ?
2. The call to figure.legend() puts the legends nicely outside the plot
boundaries (in the top right hand corner). The equivalent call to
ax.legend() places the legends inside the plot boundary. Does anyone know
a) why the behavior here is slightly different and b) how I can get the
legends outside the plot boundary using ax.legend() ?

Showing 4 results of 4

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /