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
(4)
3
(9)
4
(12)
5
(12)
6
(7)
7
(8)
8
(4)
9
(2)
10
(9)
11
(6)
12
(1)
13
(20)
14
(13)
15
(9)
16
(3)
17
(12)
18
(16)
19
(14)
20
(12)
21
(15)
22
(11)
23
(5)
24
(7)
25
(7)
26
(8)
27
(11)
28
(10)
29
(1)
30
(3)
31
(6)





Showing 12 results of 12

From: questions a. <que...@gm...> - 2011年10月04日 23:58:29
Thanks for responding. I believe quiver is more appropriate because I am
only using wind direction (at this stage) and this results in arrows.
I have had a look at the demos and still do not understand how to plot my
degrees in arrows. How do I define which angle is north, south, west, east,
etc?
Any suggestions? Thanks
from netCDF4 import Dataset
import numpy as N
import pylab as plt
from numpy import ma as MA
from mpl_toolkits.basemap import Basemap
import os
ncfile=Dataset('E:/temp_winddir/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
'NETCDF4')
WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
LAT=ncfile.variables['latitude'][:]
LON=ncfile.variables['longitude'][:]
TIME=ncfile.variables['time'][-50]
ncfile.close()
map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
 llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
x,y=LON,LAT
u=10*x
v=10*y
map.quiver(x,y,u, v, WDIR)
plt.title('Wind Direction')
plt.show()
Traceback (most recent call last):
 File "d:/plot_winddirection.py", line 22, in <module>
 map.quiver(x,y,u, v, WDIR)
 File "C:\Python27\lib\site-packages\mpl_toolkits\basemap\__init__.py",
line 3102, in quiver
 ret = ax.quiver(x,y,u,v,*args,**kwargs)
 File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 6320, in
quiver
 q = mquiver.Quiver(self, *args, **kw)
 File "C:\Python27\lib\site-packages\matplotlib\quiver.py", line 395, in
__init__
 self.XY = np.hstack((X[:,np.newaxis], Y[:,np.newaxis]))
 File "C:\Python27\lib\site-packages\numpy\core\shape_base.py", line 270,
in hstack
 return _nx.concatenate(map(atleast_1d,tup),1)
ValueError: array dimensions must agree except for d_0
On Tue, Oct 4, 2011 at 12:54 PM, Eric Firing <ef...@ha...> wrote:
> On 10/03/2011 03:00 PM, Benjamin Root wrote:
> > On Mon, Oct 3, 2011 at 6:51 PM, questions anon <que...@gm...
> > <mailto:que...@gm...>> wrote:
> >
> > Hi All,
> > Is there a simple way to plot a directional arrow to represent a
> degree?
> > I have a netcdf file containing wind direction as degrees and I
> > would like to make a plot with all little arrows representing the
> > wind direction.
> > Below is the code I am using currently to plot wind direction but am
> > not sure where/how to add directional arrows.
> > Thanks
> >
> >
> > from netCDF4 import Dataset
> > import numpy as N
> > import pylab as plt
> > from numpy import ma as MA
> > from mpl_toolkits.basemap import Basemap
> > import os
> >
> > ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> > 'NETCDF4')
> > WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> > LAT=ncfile.variables['latitude'][:]
> > LON=ncfile.variables['longitude'][:]
> > TIME=ncfile.variables['time'][-50]
> > fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
> > WDIR=MA.masked_values(WDIR, fillvalue)
> > ncfile.close()
> >
> > map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> >
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> > x,y=map(*N.meshgrid(LON,LAT))
> > map.drawstates()
> > map.drawcoastlines()
> > plt.title('Wind Direction')
> > CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
> > l,b,w,h =0.1,0.1,0.8,0.8
> > cax = plt.axes([l+w+0.025, b, 0.025, h])
> > plt.colorbar(CS,cax=cax,drawedges=True)
> > plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
> > plt.show()
> >
> >
> > Would the barb() command do what you want?
> >
> >
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
> > http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
> >
> > They aren't arrows, but they are commonly used in meteorology to plot
> > windfields.
> >
> > Cheers,
> > Ben Root
>
> There is also quiver, both in matplotlib and in basemap. See the
> quiver_demo.py and barb_demo.py in the basemap examples directory.
>
> Eric
>
> >
> >
> >
> >
> ------------------------------------------------------------------------------
> > All the data continuously generated in your IT infrastructure contains a
> > definitive record of customers, application performance, security
> > threats, fraudulent activity and more. Splunk takes this data and makes
> > sense of it. Business sense. IT sense. Common sense.
> > http://p.sf.net/sfu/splunk-d2dcopy1
> >
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Michael C. <fat...@ya...> - 2011年10月04日 22:25:09
Ryan,
I should clarify my color issue. Your code is smart enough to generate
however many colors are needed but I want to make sure the colors are all
unique.
Thanks again!
Mike
Mike, sorry to send this twice... I should have sent it to the list as
well...
_______________________________
Mike,
If your locations were integers or floats rather than strings, you could
just change the scatter call to the following:
ax.scatter(dates,IDs,c=
locations,marker='d')
I don't know about a legend... I don't know if that is possible with a
scatter plot (?). Because scatter plots get their colors based off of a
color map, you could generate a color bar for your data. You may need to
capture the collection object returned from the scatter plot function call,
though. Here's your code with these modifications:
# Of course, you need to change your locations list to integers rather than
strings.
fig = plt.figure()
ax = fig.add_subplot(111)
sc = ax.scatter(dates,IDs,c=locations,marker='d')
ax.xaxis_date()
fig.autofmt_xdate()
plt.colorbar(sc)
plt.grid(True)
plt.show()
If you really need a legend, then you could do a loop of plot commands for
each set of unique locations. Using some fancy Numpy masking makes the
process easier...
import numpy as np
import matplotlib.pyplot as plt
IDs = np.array([47, 33, 47, 12, 50, 50, 27, 27, 16, 27])
locations = np.array(['201', '207', '207', '205', '204', '201', '209',
'209', \
 '207','207'])
dates = np.array([ 733315.83240741, 733315.83521991, 733315.83681713,
 733315.83788194, 733336.54554398, 733336.54731481,
 733337.99842593, 733337.99943287, 733338.00070602,
 733338.00252315])
fig = plt.figure()
ax = fig.add_subplot(111)
cs = ['r', 'b', 'g', 'k', 'c']
for n, i in enumerate(np.unique(locations)):
 ax.plot(dates[locations==i],IDs[locations==i],'d', c=cs[n%len(cs)],
label=i)
ax.xaxis_date()
fig.autofmt_xdate()
plt.legend(numpoints=1)
plt.grid(True)
plt.show()
Not sure if this is exactly what you wanted, but I hope it helps a little.
Ryan
-- 
View this message in context: http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32592799.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Michael C. <fat...@ya...> - 2011年10月04日 21:58:05
Ryan,
I have tried setting c=locations (after converting to float) and gotten
inconsistent results. For a dataset with ~32,000 points it seems to work,
but a 2nd dataset of ~100,000 points colors everything the same even though
there are at least 10 locations.
Your second idea works nicely and I'm going to try applying it to my data.
The only real issue is that I don't know how many locations there will be
for each plot so I can't hard code the colors list. I think I can figure
that part out though.
Thanks!
Mike
Mike, sorry to send this twice... I should have sent it to the list as
well...
_______________________________
Mike,
If your locations were integers or floats rather than strings, you could
just change the scatter call to the following:
ax.scatter(dates,IDs,c=
locations,marker='d')
I don't know about a legend... I don't know if that is possible with a
scatter plot (?). Because scatter plots get their colors based off of a
color map, you could generate a color bar for your data. You may need to
capture the collection object returned from the scatter plot function call,
though. Here's your code with these modifications:
# Of course, you need to change your locations list to integers rather than
strings.
fig = plt.figure()
ax = fig.add_subplot(111)
sc = ax.scatter(dates,IDs,c=locations,marker='d')
ax.xaxis_date()
fig.autofmt_xdate()
plt.colorbar(sc)
plt.grid(True)
plt.show()
If you really need a legend, then you could do a loop of plot commands for
each set of unique locations. Using some fancy Numpy masking makes the
process easier...
import numpy as np
import matplotlib.pyplot as plt
IDs = np.array([47, 33, 47, 12, 50, 50, 27, 27, 16, 27])
locations = np.array(['201', '207', '207', '205', '204', '201', '209',
'209', \
 '207','207'])
dates = np.array([ 733315.83240741, 733315.83521991, 733315.83681713,
 733315.83788194, 733336.54554398, 733336.54731481,
 733337.99842593, 733337.99943287, 733338.00070602,
 733338.00252315])
fig = plt.figure()
ax = fig.add_subplot(111)
cs = ['r', 'b', 'g', 'k', 'c']
for n, i in enumerate(np.unique(locations)):
 ax.plot(dates[locations==i],IDs[locations==i],'d', c=cs[n%len(cs)],
label=i)
ax.xaxis_date()
fig.autofmt_xdate()
plt.legend(numpoints=1)
plt.grid(True)
plt.show()
Not sure if this is exactly what you wanted, but I hope it helps a little.
Ryan
-- 
View this message in context: http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32592621.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Jens N. <JN...@Ro...> - 2011年10月04日 14:15:24
Hi Nils.
I have never tried to do a real printout, so I am no expert here. My use case was almost always to directly create pdf or ps documents, which can be done nicely using the several print_* methods of the figurecanvas.
You can use Actions for your case instead of a widget. Actually they should considered to be recommended when using Qt4. Actions are a very elegant way to attach functionality to a program.
So define an action like you suggested, and add it to the toolbar using the addAction method of the toolbar.
Then you might want to implement a slot, that you in turn connect to the "triggered" signal of your action, which implements the real printing.
I can't really help you with the printing itself, but have found an implemented strategy after a bit googling. That might be a start ...
http://gotm.git.sourceforge.net/git/gitweb.cgi?p=gotm/gotm;a=blob;f=gui.py/xmlplot/gui_qt4.py;h=6e0239a958580ac2a35cd26653d83f26909fda24;hb=163207fa3fcc86f91008056c77e9c31fd6a9e246
Have a look at the onPrint method here.
Hoping again that this was helpful.
Jens
-----Original Message-----
From: Nils Wagner [mailto:nw...@ia...] 
Sent: Tuesday, October 04, 2011 11:08 AM
To: Jens Nie
Cc: mat...@li...
Subject: Re: [Matplotlib-users] Customizing the Navigation toolbar
On Tue, 4 Oct 2011 10:09:57 +0200
 Jens Nie <JN...@Ro...> wrote:
> Hi Nils.
> 
> The Qt based Navigation toolbar is just a Qt Widget with a proper 
>layout already set. So you should be able to add any Qt widget to the 
>toolbar using its addWidget method.
> I was able to add a simple line edit (without any use) like so:
> 
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> 
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as 
>FigureCanvas from matplotlib.backends.backend_qt4agg import 
>NavigationToolbar2QT as NavigationToolbar2
> 
> class ViewWidget(QMainWindow):
> def __init__(self):
> QMainWindow.__init__(self)
> 
> # create a simple main widget to keep the figure
> self.mainWidget = QWidget()
> self.setCentralWidget(self.mainWidget)
> 
> layout = QVBoxLayout()
> self.mainWidget.setLayout(layout)
> 
> # create a figure
> self.figure_canvas = FigureCanvas(Figure())
> layout.addWidget(self.figure_canvas, 10)
> 
> # and the axes for the figure
> self.axes =
>self.figure_canvas.figure.add_subplot(111)
> 
> # add a navigation toolbar
> self.navigation_toolbar =
>NavigationToolbar2(self.figure_canvas, self)
> layout.addWidget(self.navigation_toolbar, 0)
> 
> # create a simple widget to extend the navigation toolbar
> anotherWidget=QLineEdit()
> # add the new widget to the existing navigation toolbar
> self.navigation_toolbar.addWidget(anotherWidget)
> 
> if __name__=="__main__":
> app=QApplication(sys.argv)
> mw=ViewWidget()
> mw.show()
> sys.exit(app.exec_())
> 
> Hope that helps ...
> 
> Best regards
> 
> Jens
> 
Hi Jens,
Thank you very much for your response.
Hence I have tried
import sys
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
 def __init__(self):
 QMainWindow.__init__(self)
 # create a simple main widget to keep the figure
 self.mainWidget = QWidget()
 self.setCentralWidget(self.mainWidget)
 layout = QVBoxLayout()
 self.mainWidget.setLayout(layout)
 # create a figure
 self.figure_canvas = FigureCanvas(Figure())
 layout.addWidget(self.figure_canvas, 10)
 # and the axes for the figure
 self.axes =
self.figure_canvas.figure.add_subplot(111)
 x = np.linspace(0.,2*np.pi,100)
 self.axes.plot(x,np.sin(x))
 # add a navigation toolbar
 self.navigation_toolbar =
NavigationToolbar2(self.figure_canvas, self)
 layout.addWidget(self.navigation_toolbar, 0)
 # create a simple widget to extend the navigation toolbar
# anotherWidget=QLineEdit()
 printer = QPrinter()
 anotherWidget= QPrintDialog(printer,self)
 # add the new widget to the existing navigation toolbar
 self.navigation_toolbar.addWidget(anotherWidget)
if __name__=="__main__":
 app=QApplication(sys.argv)
 mw=ViewWidget()
 mw.show()
 sys.exit(app.exec_())
How do I connect the plot with the printer ?
How can I replace the printer dialog by a small icon ?
I found the lines
 a = self.addAction(self._icon('filesave.svg'),
'Save',
 self.save_figure)
in backend_qt4.py
Nils
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: John L. <joh...@sb...> - 2011年10月04日 09:09:56
On Mon, 2011年10月03日 at 12:49 -0700, Michael Castleton wrote:
> Hello,
> I am using Matplotlib 1.0.0 in Python 2.6.
> I am trying to plot time series data of unique IDs and color the points
> based on location. Each data point has a unique ID value, a date value, and
> a location value.
> The unique IDs and date values are plotting fine but I am unable to control
> the color and subsequently the legend.
> I've been trying to figure out how to set color = locations with no success.
> Any ideas out there?
Michael, if I were you, I would reorganize and group your data into
several separate scatter data sets, based on the location parameter.
Then, color each SET the color that you want. Here's a start, from the
data as you provided it:
>>> points = [(a, b, c) for a, b, c in zip(locations, IDs, dates)]
>>> for p in points:
 print p
('201', 47, 733315.83240741002)
('207', 33, 733315.83521991002)
('207', 47, 733315.83681712998)
('205', 12, 733315.83788193995)
('204', 50, 733336.54554397997)
('201', 50, 733336.54731480998)
('209', 27, 733337.99842593004)
('209', 27, 733337.99943286995)
('207', 16, 733338.00070602004)
('207', 27, 733338.00252314995)
>>> def make_dict(lst):
 d = {}
 for a, b, c in lst:
	 try:
 d[a][0].append(b)
 d[a][1].append(c)
 except KeyError:
 d[a] = ([b],[c])
 return d
>>> collated = make_dict(points)
>>> for k in collated:
 print k, collated[k]
201 ([47, 50], [733315.83240741002, 733336.54731480998])
209 ([27, 27], [733337.99842593004, 733337.99943286995])
205 ([12], [733315.83788193995])
204 ([50], [733336.54554397997])
207 ([33, 47, 16, 27], [733315.83521991002, 733315.83681712998,
733338.00070602004, 733338.00252314995])
>From collated, you could then plot five scattergrams, each of a
different color, in the same axes object.
From: Nils W. <nw...@ia...> - 2011年10月04日 09:08:25
On Tue, 4 Oct 2011 10:09:57 +0200
 Jens Nie <JN...@Ro...> wrote:
> Hi Nils.
> 
> The Qt based Navigation toolbar is just a Qt Widget with 
>a proper layout already set. So you should be able to add 
>any Qt widget to the toolbar using its addWidget method.
> I was able to add a simple line edit (without any use) 
>like so:
> 
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> 
> from matplotlib.figure import Figure
> from matplotlib.backends.backend_qt4agg import 
>FigureCanvasQTAgg as FigureCanvas
> from matplotlib.backends.backend_qt4agg import 
>NavigationToolbar2QT as NavigationToolbar2
> 
> class ViewWidget(QMainWindow):
> def __init__(self):
> QMainWindow.__init__(self)
> 
> # create a simple main widget to keep the figure
> self.mainWidget = QWidget()
> self.setCentralWidget(self.mainWidget)
> 
> layout = QVBoxLayout()
> self.mainWidget.setLayout(layout)
> 
> # create a figure
> self.figure_canvas = FigureCanvas(Figure())
> layout.addWidget(self.figure_canvas, 10)
> 
> # and the axes for the figure
> self.axes = 
>self.figure_canvas.figure.add_subplot(111)
> 
> # add a navigation toolbar
> self.navigation_toolbar = 
>NavigationToolbar2(self.figure_canvas, self)
> layout.addWidget(self.navigation_toolbar, 0)
> 
> # create a simple widget to extend the navigation 
>toolbar
> anotherWidget=QLineEdit()
> # add the new widget to the existing navigation 
>toolbar
> self.navigation_toolbar.addWidget(anotherWidget)
> 
> if __name__=="__main__":
> app=QApplication(sys.argv)
> mw=ViewWidget()
> mw.show()
> sys.exit(app.exec_())
> 
> Hope that helps ...
> 
> Best regards
> 
> Jens
> 
Hi Jens,
Thank you very much for your response.
Hence I have tried
import sys
import numpy as np
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import 
FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import 
NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
 def __init__(self):
 QMainWindow.__init__(self)
 # create a simple main widget to keep the figure
 self.mainWidget = QWidget()
 self.setCentralWidget(self.mainWidget)
 layout = QVBoxLayout()
 self.mainWidget.setLayout(layout)
 # create a figure
 self.figure_canvas = FigureCanvas(Figure())
 layout.addWidget(self.figure_canvas, 10)
 # and the axes for the figure
 self.axes = 
self.figure_canvas.figure.add_subplot(111)
 x = np.linspace(0.,2*np.pi,100)
 self.axes.plot(x,np.sin(x))
 # add a navigation toolbar
 self.navigation_toolbar = 
NavigationToolbar2(self.figure_canvas, self)
 layout.addWidget(self.navigation_toolbar, 0)
 # create a simple widget to extend the navigation 
toolbar
# anotherWidget=QLineEdit()
 printer = QPrinter()
 anotherWidget= QPrintDialog(printer,self)
 # add the new widget to the existing navigation 
toolbar
 self.navigation_toolbar.addWidget(anotherWidget)
if __name__=="__main__":
 app=QApplication(sys.argv)
 mw=ViewWidget()
 mw.show()
 sys.exit(app.exec_())
How do I connect the plot with the printer ?
How can I replace the printer dialog by a small icon ?
I found the lines
 a = self.addAction(self._icon('filesave.svg'), 
'Save',
 self.save_figure)
in backend_qt4.py
Nils
From: Jens N. <JN...@Ro...> - 2011年10月04日 08:30:46
Hi Nils.
The Qt based Navigation toolbar is just a Qt Widget with a proper layout already set. So you should be able to add any Qt widget to the toolbar using its addWidget method.
I was able to add a simple line edit (without any use) like so:
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar2
class ViewWidget(QMainWindow):
 def __init__(self):
 QMainWindow.__init__(self)
 
 # create a simple main widget to keep the figure
 self.mainWidget = QWidget()
 self.setCentralWidget(self.mainWidget)
 layout = QVBoxLayout()
 self.mainWidget.setLayout(layout)
 # create a figure
 self.figure_canvas = FigureCanvas(Figure())
 layout.addWidget(self.figure_canvas, 10)
 # and the axes for the figure
 self.axes = self.figure_canvas.figure.add_subplot(111)
 # add a navigation toolbar
 self.navigation_toolbar = NavigationToolbar2(self.figure_canvas, self)
 layout.addWidget(self.navigation_toolbar, 0)
 # create a simple widget to extend the navigation toolbar
 anotherWidget=QLineEdit()
 # add the new widget to the existing navigation toolbar
 self.navigation_toolbar.addWidget(anotherWidget)
 
if __name__=="__main__":
 app=QApplication(sys.argv)
 mw=ViewWidget()
 mw.show()
 sys.exit(app.exec_())
Hope that helps ...
Best regards
Jens
-----Original Message-----
From: Nils Wagner [mailto:nw...@ia...] 
Sent: Thursday, September 29, 2011 2:56 PM
To: mat...@li...
Subject: [Matplotlib-users] Customizing the Navigation toolbar
Hi all,
How can I add a printer button to the Navigation toolbar http://matplotlib.sourceforge.net/users/navigation_toolbar.html
?
A small example for QT would be awesome.
Thanks in advance.
 Nils
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Matplotlib-users mailing list
Mat...@li...
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Ryan N. <rne...@gm...> - 2011年10月04日 04:41:44
Mike, sorry to send this twice... I should have sent it to the list as
well...
_______________________________
Mike,
If your locations were integers or floats rather than strings, you could
just change the scatter call to the following:
ax.scatter(dates,IDs,c=
locations,marker='d')
I don't know about a legend... I don't know if that is possible with a
scatter plot (?). Because scatter plots get their colors based off of a
color map, you could generate a color bar for your data. You may need to
capture the collection object returned from the scatter plot function call,
though. Here's your code with these modifications:
# Of course, you need to change your locations list to integers rather than
strings.
fig = plt.figure()
ax = fig.add_subplot(111)
sc = ax.scatter(dates,IDs,c=locations,marker='d')
ax.xaxis_date()
fig.autofmt_xdate()
plt.colorbar(sc)
plt.grid(True)
plt.show()
If you really need a legend, then you could do a loop of plot commands for
each set of unique locations. Using some fancy Numpy masking makes the
process easier...
import numpy as np
import matplotlib.pyplot as plt
IDs = np.array([47, 33, 47, 12, 50, 50, 27, 27, 16, 27])
locations = np.array(['201', '207', '207', '205', '204', '201', '209',
'209', \
 '207','207'])
dates = np.array([ 733315.83240741, 733315.83521991, 733315.83681713,
 733315.83788194, 733336.54554398, 733336.54731481,
 733337.99842593, 733337.99943287, 733338.00070602,
 733338.00252315])
fig = plt.figure()
ax = fig.add_subplot(111)
cs = ['r', 'b', 'g', 'k', 'c']
for n, i in enumerate(np.unique(locations)):
 ax.plot(dates[locations==i],IDs[locations==i],'d', c=cs[n%len(cs)],
label=i)
ax.xaxis_date()
fig.autofmt_xdate()
plt.legend(numpoints=1)
plt.grid(True)
plt.show()
Not sure if this is exactly what you wanted, but I hope it helps a little.
Ryan
On Mon, Oct 3, 2011 at 2:49 PM, Michael Castleton <fat...@ya...>wrote:
>
> Hello,
> I am using Matplotlib 1.0.0 in Python 2.6.
> I am trying to plot time series data of unique IDs and color the points
> based on location. Each data point has a unique ID value, a date value, and
> a location value.
> The unique IDs and date values are plotting fine but I am unable to control
> the color and subsequently the legend.
>
> Here is a sample of the data.
> IDs = [47, 33, 47, 12, 50, 50, 27, 27, 16, 27]
> locations = ['201', '207', '207', '205', '204', '201', '209', '209',
> '207','207']
> dates = [ 733315.83240741, 733315.83521991, 733315.83681713,
> 733315.83788194, 733336.54554398, 733336.54731481,
> 733337.99842593, 733337.99943287, 733338.00070602,
> 733338.00252315]
>
> This basic code works.
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
> ax.scatter(dates,IDs,marker='d')
> ax.xaxis_date()
> fig.autofmt_xdate()
> plt.grid(True)
> plt.show()
>
> I've been trying to figure out how to set color = locations with no
> success.
> Any ideas out there?
> Thanks,
>
> Mike
> --
> View this message in context:
> http://old.nabble.com/color-problems-in-scatter-plot-tp32584727p32584727.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Jae-Joon L. <lee...@gm...> - 2011年10月04日 02:17:34
On Tue, Oct 4, 2011 at 4:22 AM, Christopher Brown <c-...@as...> wrote:
>   tick.label1.set_color('red')
>
You should use tick.label2, not tick.label1.
 tick.label2.set_color('red')
Anyhow, as Eric said, it is strongly advised to use the tick_params method.
-JJ
From: Eric F. <ef...@ha...> - 2011年10月04日 01:54:41
On 10/03/2011 03:00 PM, Benjamin Root wrote:
> On Mon, Oct 3, 2011 at 6:51 PM, questions anon <que...@gm...
> <mailto:que...@gm...>> wrote:
>
> Hi All,
> Is there a simple way to plot a directional arrow to represent a degree?
> I have a netcdf file containing wind direction as degrees and I
> would like to make a plot with all little arrows representing the
> wind direction.
> Below is the code I am using currently to plot wind direction but am
> not sure where/how to add directional arrows.
> Thanks
>
>
> from netCDF4 import Dataset
> import numpy as N
> import pylab as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
> ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> 'NETCDF4')
> WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> LAT=ncfile.variables['latitude'][:]
> LON=ncfile.variables['longitude'][:]
> TIME=ncfile.variables['time'][-50]
> fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
> WDIR=MA.masked_values(WDIR, fillvalue)
> ncfile.close()
>
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=map(*N.meshgrid(LON,LAT))
> map.drawstates()
> map.drawcoastlines()
> plt.title('Wind Direction')
> CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
> l,b,w,h =0.1,0.1,0.8,0.8
> cax = plt.axes([l+w+0.025, b, 0.025, h])
> plt.colorbar(CS,cax=cax,drawedges=True)
> plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
> plt.show()
>
>
> Would the barb() command do what you want?
>
> http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
> http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
>
> They aren't arrows, but they are commonly used in meteorology to plot
> windfields.
>
> Cheers,
> Ben Root
There is also quiver, both in matplotlib and in basemap. See the 
quiver_demo.py and barb_demo.py in the basemap examples directory.
Eric
>
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: John L. <joh...@sb...> - 2011年10月04日 01:11:27
Following up to my own post:
First, Sourceforge's listserv did not like the link to my animation.
Let my try again, with a shortened link:
http://flic.kr/p/an4oyo
Second:
> The indirect nature of this redrawing-by-sizing approach
> sent me on a long and pointless hunt for bugs in my own code.
Putting this another way -- explicit is better than implicit!
From: Benjamin R. <ben...@ou...> - 2011年10月04日 01:01:04
On Mon, Oct 3, 2011 at 6:51 PM, questions anon <que...@gm...>wrote:
> Hi All,
> Is there a simple way to plot a directional arrow to represent a degree?
> I have a netcdf file containing wind direction as degrees and I would like
> to make a plot with all little arrows representing the wind direction.
> Below is the code I am using currently to plot wind direction but am not
> sure where/how to add directional arrows.
> Thanks
>
>
> from netCDF4 import Dataset
> import numpy as N
> import pylab as plt
> from numpy import ma as MA
> from mpl_toolkits.basemap import Basemap
> import os
>
> ncfile=Dataset('E:/WINDDIR/IDZ00026_VIC_ADFD_Wind_Dir_SFC.nc', 'r+',
> 'NETCDF4')
> WDIR=ncfile.variables['Wind_Dir_SFC'][-50]
> LAT=ncfile.variables['latitude'][:]
> LON=ncfile.variables['longitude'][:]
> TIME=ncfile.variables['time'][-50]
> fillvalue=ncfile.variables['Wind_Dir_SFC']._FillValue
> WDIR=MA.masked_values(WDIR, fillvalue)
> ncfile.close()
>
> map = Basemap(projection='merc',llcrnrlat=-40,urcrnrlat=-33,
> llcrnrlon=139.0,urcrnrlon=151.0,lat_ts=0,resolution='i')
> x,y=map(*N.meshgrid(LON,LAT))
> map.drawstates()
> map.drawcoastlines()
> plt.title('Wind Direction')
> CS = map.contourf(x,y,WDIR,15, cmap=plt.cm.jet)
> l,b,w,h =0.1,0.1,0.8,0.8
> cax = plt.axes([l+w+0.025, b, 0.025, h])
> plt.colorbar(CS,cax=cax,drawedges=True)
> plt.savefig((os.path.join('E:/WINDDIR/', 'WDIRSFC.png')))
> plt.show()
>
>
Would the barb() command do what you want?
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.barbs
http://matplotlib.sourceforge.net/examples/pylab_examples/barb_demo.html
They aren't arrows, but they are commonly used in meteorology to plot
windfields.
Cheers,
Ben Root

Showing 12 results of 12

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 によって変換されたページ (->オリジナル) /