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




Showing 8 results of 8

From: Christopher B. <Chr...@no...> - 2007年07月02日 21:57:04
I don't know how to do it with the MPL agg back-end, but I think you 
mentioned wx, and you can do it there instead. a wxImage can be 
constructed from a buffer object, then saved as a PNG. You may need to 
set the rgb and alpha portions separately. See the wxPython wiki and 
search for "Image".
Also:
> matrix = []
> buffer = self.get_renderer().tostring_argb()
> l, h = self.GetSize()
> for ligne in xrange(h):
> matrix.append([])
> for colonne in xrange(l):
> i = 4*(ligne*h + colonne)
> pixel = buffer[i:i+4]
> matrix[-1].append(pixel)
This is a very slow way to create the numpy array!
Option a: first create an empty array:
matrix = numpy.empty((l,h,4), numpy.byte)
then fill that in. but even better:
you can build the array directly from the buffer string:
matrix = numpy.fromstring(buffer, dtype=numpy.byte)
lotlib-users
-- 
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
From: Matthias M. <Mat...@gm...> - 2007年07月02日 21:50:21
Hello everybody,
first of all I hope my mails on the issue 'Prompt/TextBox/InputButton' don't 
become to many. 
But I had one more idea and I want to share it with you.
If you don't like my usage of lists as a pointer to variables, one could 
replace this in two steps: 
1) Adding a new method 'get_text' to get the actual label text 
(def get_text(self): 
 return self.label.get_text() )
2) In the example one would include a function to set one's variable to the 
evaluated label-text. Than one would add this function into the 
self.observers and so call it after every finished typing mode.
This new behaviour has the big advance that error-handling during evaluation 
of the text is a task for users and not to mpl. 
I hope I could explain my idea ...
best regards,
Matthias
On Wednesday 27 June 2007 18:19, Matthias Michler wrote:
> Hello everybody,
>
> in my last version I forgot to include a very useful function (it is
> comparable with the 'Button.on_clicked' function). I added it now. It
> allows the user to interact with other widgets ( I needed it to interact
> with the Silder) or his own program (e.g. updating external values or
> plots).
>
> I attached this new version.
>
> best regards,
> Matthias
>
> On Tuesday 26 June 2007 19:46, Matthias Michler wrote:
> > Hello John,
> > Hello all,
> >
> > I thought once more about the textbox and added some of your (Johns)
> > features to my class 'InputButton'. Probably my solution isn't the best
> > possible, but I attached this version to express what I'm thinking of and
> > to see what others think about my solution and needed skills of the
> > textbox .
> >
> > Could this be helpful / useful for others?
> >
> > best regards,
> > Matthias
> >
> > On Wednesday 06 June 2007 17:25, John Hunter wrote:
> > > On 6/6/07, Matthias Michler <Mat...@gm...> wrote:
> > > > By the way: What do you think about the "insert a 'l' or 'g' into
> > > > your TextBox and get a grid or log-scale"-issue? Is there a
> > > > possibility to switch the mpl-meaning of 'l', 'g' and 'f' off?
> > >
> > > Yes, this is clearly an issue that has to be dealt with in a cleanup.
> > > The current implementation has no concept of whether the text box is
> > > the active widget. We would need to do something like activate the
> > > text box when you click on it (and figure out the right cursor
> > > location based on the click if there is already text in there) and
> > > deactivate it on a carriage return or click in another axes. The
> > > current implementation was only a proof of concept.
> > >
> > > JDH
From: Eric F. <ef...@ha...> - 2007年07月02日 20:36:50
Andrew McLean wrote:
[...]
> Dorling cartograms described here (with an example near the bottom of 
> the page):
> 
> http://www.ncgia.ucsb.edu/projects/Cartogram_Central/types.html
Thanks for the link.
Eric
> 
> Regards,
> 
> Andrew
From: Jonathan G. <jon...@gr...> - 2007年07月02日 20:24:40
In matplotlib 0.90.1 the behavior of legend() seems to have changed.
Here's a test code fragment:
---------------------------
import pylab
import numpy
y=numpy.arange(-10,10)**2
print y
pylab.plot(y)
pylab.legend()
pylab.show()
---------------------------
Running on python 2.5.1, matplotlib 0.90.0 gives me a reasonable-looking
legend in upper right corner with label "line0".
matplotlib 0.90.1 gives an empty rectangular box, fairly large, right in
the middle of the plot.
Attempting to move the legend with loc=2 or whatever has no effect.
However, giving an explicit label ( pylab.legend(['line1']) ) makes it
start working the same as 0.90.0.
I started looking at the source but don't have time today to understand
how this is supposed to work. Maybe later.
Is this the intended behavior? The announcement for 0.90.1 says:
"Display only meaningful labels when calling legend() without args."
It's not clear to me what this means.
-- 
 Jonathan Griffitts
AnyWare Engineering Boulder, CO, USA
From: Andrew M. <an...@an...> - 2007年07月02日 19:49:17
Eric Firing wrote:
> Andrew McLean wrote:
>> It all works. However, I saw in the API documentation (and the source)
>> that there is a Circle object in patch. I was hoping that using this
>> rather than polygons would give better quality output and possibly
>> smaller files. Now I can instantiate it
>>
>> circle = Circle((x,y), c[3], facecolor=cmapper.to_rgba(v))
>>
>> but can't work out what to do with it! I've tried
>>
>> ax.add_patch( circle )
>
> This works for me in the sense that I can put circles or ellipses on a 
> plot. Note that if you are trying to do this interactively you need 
> to explicitly call draw() or draw_if_interactive() (pylab functions) 
> after the call to add_patch, because the axis methods differ from 
> pylab functions in that the latter automatically call 
> draw_if_interactive() but the former do not.
>
That was useful. Thanks. Turns out the problem was that I wasn't setting 
the axis limits. I added:
 axis([xmin, xmax, ymin, ymax])
and it all worked.
> The circle in data coordinates is a circle, however, only if you use a 
> 1:1 aspect ratio. Does this suit your needs? If so you can get it 
> with the pylab axis('equal') or axis('scaled') command. Or do you 
> really want to specify the radius of the circle in x-data units or in 
> y-data units? (I have no idea what a Dorling Cartogram is.)
I was using axis('equal'). And yes this is what I want ;-). The x and y 
data units should map to the same physical scale and the radius is in 
those units.
Dorling cartograms described here (with an example near the bottom of 
the page):
http://www.ncgia.ucsb.edu/projects/Cartogram_Central/types.html
Regards,
Andrew
From: Angel L. <an...@gm...> - 2007年07月02日 09:49:59
Hello,
I started using pylab-matplotlib some weeks ago. And it is really good.
I'm working now on windows (TkAgg).
I have written a small app that reads a file and plot it. User can
press a key to read another file, and plot it over. The problem is
that the I have to resize the plot window to see the new plotted line.
Here is the code:
import sys
import os
import tkFileDialog
import pylab
pylab.hold(1)
path='E:\\Nima'
def keyp(event):
 global path
 if event.key.lower()=='o':
 fin = tkFileDialog.askopenfilename(initialdir=path)
 path=os.path.split(fin)[0]
 plot2(fin)
def plot2(fin):
 global myplot
 f=file(fin, 'r')
 lines=f.readlines()
 f.close()
 X=[]
 Y=[]
 for line in lines[1:]:
 line=line.replace(',', '.')
 X.append(float(line.split('\t')[2]))
 Y.append(float(line.split('\t')[5]))
 myplot.plot(X, Y)
 myplot.grid()
 myplot.draw()
if __name__=='__main__':
 myplot=pylab.subplot(111)
 kid=pylab.connect('key_press_event', keyp)
 pylab.xlabel('Area [A2/molecule]')
 pylab.ylabel('SP [mN/m]')
 fin = tkFileDialog.askopenfilename(initialdir=path)
 path=os.path.split(fin)[0]
 pylab.show()
 plot2(fin)
Thanks in advance for your help.
From: Eric F. <ef...@ha...> - 2007年07月02日 07:21:10
Andrew McLean wrote:
> I'm a new user of matplotlib (athough I have been using both Matlab and
> Python for years).
> 
> I have an application where I need to display data as a set of filled
> circles. The centre and the radius of the circles are both specified in
> data coordinates. The data points have an additional scalar attribute,
> which is displayed using a pseudo-colour mapping.
> 
> I've hacked something together where the circles are approximated by
> polygons using either the axis fill method or the pylab fill function. I
> select the colour by calling the get_rgba method of a ScalarMappable
> object. In the following code snippet c is a tuple containg the x and y
> coords of the centre of the circle, the radius, and a scalar "value"
> 
> theta = arange(numSegs+1) * 2.0 * math.pi / numSegs
> cos_theta = cos(theta)
> sin_theta = sin(theta)
> for c in cart:
> x = c[1] + c[3] * cos_theta
> y = c[2] + c[3] * sin_theta
> v = c[4]
> fill(x, y, facecolor=mapper.to_rgba(v), linewidth=0.5)
> 
> It all works. However, I saw in the API documentation (and the source)
> that there is a Circle object in patch. I was hoping that using this
> rather than polygons would give better quality output and possibly
> smaller files. Now I can instantiate it
> 
> circle = Circle((x,y), c[3], facecolor=cmapper.to_rgba(v))
> 
> but can't work out what to do with it! I've tried
> 
> ax.add_patch( circle )
This works for me in the sense that I can put circles or ellipses on a 
plot. Note that if you are trying to do this interactively you need to 
explicitly call draw() or draw_if_interactive() (pylab functions) after 
the call to add_patch, because the axis methods differ from pylab 
functions in that the latter automatically call draw_if_interactive() 
but the former do not.
The circle in data coordinates is a circle, however, only if you use a 
1:1 aspect ratio. Does this suit your needs? If so you can get it with 
the pylab axis('equal') or axis('scaled') command. Or do you really want 
to specify the radius of the circle in x-data units or in y-data units? 
 (I have no idea what a Dorling Cartogram is.)
> 
> and also
> 
> trans = blend_xy_sep_transform( ax.transAxes, ax.transData )
This doesn't sound like what you want at all; it is used when you want 
to specify the x-coordinate in normalized axes units and the 
y-coordinate in data units.
Eric
> circle.set_transform( trans )
> ax.add_patch( circle )
> 
> Neither work. Any ideas?
> 
> Regards,
> 
> Andrew
From: Andrew M. <and...@an...> - 2007年07月02日 00:09:58
Steve,
I guess I should have highlighted the difference. For my application I 
need the circle radii to be given in data coordinates. For the curious, 
I'm plotting something very similar to Dorling Cartograms. I did look in 
the source of "scatter" for clues, but it uses a 20 sided polygon to 
approximate a circle. It looks like scatter_classic did what I wanted, 
but that's been removed :-(.
- Andrew
Stephen George wrote:
> It *seems* like it already does what you are trying to do?, maybe I'm 
> missing something in my understanding.
>
> Steve
>
>
>
> Andrew McLean wrote:
>> I'm a new user of matplotlib (athough I have been using both Matlab and
>> Python for years).
>>
>> I have an application where I need to display data as a set of filled
>> circles. The centre and the radius of the circles are both specified in
>> data coordinates. The data points have an additional scalar attribute,
>> which is displayed using a pseudo-colour mapping.
>>
>> I've hacked something together where the circles are approximated by
>> polygons using either the axis fill method or the pylab fill function. I
>> select the colour by calling the get_rgba method of a ScalarMappable
>> object. In the following code snippet c is a tuple containg the x and y
>> coords of the centre of the circle, the radius, and a scalar "value"
>>
>> theta = arange(numSegs+1) * 2.0 * math.pi / numSegs
>> cos_theta = cos(theta)
>> sin_theta = sin(theta)
>> for c in cart:
>> x = c[1] + c[3] * cos_theta
>> y = c[2] + c[3] * sin_theta
>> v = c[4]
>> fill(x, y, facecolor=mapper.to_rgba(v), linewidth=0.5)
>>
>> It all works. However, I saw in the API documentation (and the source)
>> that there is a Circle object in patch. I was hoping that using this
>> rather than polygons would give better quality output and possibly
>> smaller files. Now I can instantiate it
>>
>> circle = Circle((x,y), c[3], facecolor=cmapper.to_rgba(v))
>>
>> but can't work out what to do with it! I've tried
>>
>> ax.add_patch( circle )
>>
>> and also
>>
>> trans = blend_xy_sep_transform( ax.transAxes, ax.transData )
>> circle.set_transform( trans )
>> ax.add_patch( circle )
>>
>> Neither work. Any ideas?
>>
>> Regards,
>>
>> Andrew
>>
>>

Showing 8 results of 8

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