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

Showing 23 results of 23

From: Christopher B. <Chr...@no...> - 2007年06月11日 21:01:04
John Hunter wrote:
> BTW, numpy gurus, is there a better way to find the index in an array
> that is minimal than
> 
> indmin = int(numpy.nonzero(distances.min()==distances)[0])
yes -- see below. Also a few tweaks:
> distances = numpy.array(numpy.sqrt((x-xs[event.ind])**2. +
> (y-ys[event.ind])**2))
No need to call numpy.array on that, you're making a copy of what must 
be an array already. By the way, if you're not sure if it's an array, 
then you can use numpy.asarray(a) which won't make a copy if the 
argument is already an array.
You can also use numpy.hypot() rather than explicitly calling 
sqrt(SumOfSquares):
distances = numpy.hypot(x-xs[event.ind], y-ys[event.ind] )
(untested)
or, if all you want is the closest one, you don't need to take the 
sqrt() at all:
distances = ( (x-xs[event.ind])**2 + (y-ys[event.ind])**2 )
And don't use "2." in an exponent -- I think there is some optimization 
for integer exponents.
> indmin = int(numpy.nonzero(distances.min()==distances)[0])
here you can use argmin:
indmin = numpy.argmin(distances)
of course, what you'd really want is a spatial index....
All untested....
-Chris
-- 
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: John H. <jd...@gm...> - 2007年06月11日 20:50:43
On 6/10/07, rolandreichel <rol...@we...> wrote:
> I want to plot some timeseries (eg. stockcharts). I use now
> DateLocator/Formatter, it works fine for me with the exeption, that
> dataless periods on X-Axis (eg. weekends) are also plotted. Is there an
> easy way to suppress them?
Plot numpy.arange(len(xdata)) vs y and use a custom tick locator to
format the integer index to date strings. Some of the code below is
using svn (eg the csv2rec stuff) but the core logic of formatting date
strings from integers works with any reasonably current mpl.
# plot dates evenly spaced, eg skipping weekends
import numpy
from matplotlib.mlab import csv2rec
from pylab import figure, show
from matplotlib.dates import Formatter
r = csv2rec('data/msft.csv')[-40:]
class MyFormatter(Formatter):
 def __init__(self, dates, fmt='%Y-%m-%d'):
 self.dates = dates
 self.fmt = fmt
 def __call__(self, x, pos=0):
 'Return the label for time x at position pos'
 ind = int(round(x))
 if ind>=len(self.dates) or ind<=0: return ''
 return self.dates[ind].strftime(self.fmt)
formatter = MyFormatter(r.date)
fig = figure()
ax = fig.add_subplot(111)
ax.xaxis.set_major_formatter(formatter)
ax.plot(numpy.arange(len(r)), r.close, 'o-')
fig.autofmt_xdate()
show()
From: John H. <jd...@gm...> - 2007年06月11日 20:36:07
Attachments: test.py
On 6/11/07, Trevis Crane <t_...@mr...> wrote:
> I've coded (with help from John) a plot of mine to allow a user to select a
> data point, and when they click on it a new plot pops up. It works great.
> However, some of the points are very close together and if I'm not extremely
> careful in selecting the point, then multiple graphs pop up or I get the
> wrong one entirely.
You can always write a custom hit testing function -- see
http://matplotlib.sourceforge.net/examples/pick_event_demo.py for an
example.
Probably easiest here is to just find the index which is closest to
one of your data points and just plot that data set.
BTW, numpy gurus, is there a better way to find the index in an array
that is minimal than
indmin = int(numpy.nonzero(distances.min()==distances)[0])
import numpy
from pylab import figure, show
X = numpy.random.rand(100, 200)
xs = numpy.mean(X, axis=1)
ys = numpy.std(X, axis=1)
fig = figure()
ax = fig.add_subplot(211)
ax.set_title('click on point to plot time series')
line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance
ax2 = fig.add_subplot(212)
def onpick(event):
 if event.artist!=line: return True
 N = len(event.ind)
 if not N: return True
 # the click locations
 x = event.mouseevent.xdata
 y = event.mouseevent.ydata
 distances = numpy.array(numpy.sqrt((x-xs[event.ind])**2. +
(y-ys[event.ind])**2))
 indmin = int(numpy.nonzero(distances.min()==distances)[0])
 dataind = event.ind[indmin]
 print event.ind, distances, indmin, dataind, X[dataind][:5]
 ax2.cla()
 ax2.plot(X[dataind])
 ax2.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f'%(xs[dataind], ys[dataind]),
 transform=ax2.transAxes, va='top')
 ax2.set_ylim(-0.5, 1.5)
 fig.canvas.draw()
 return True
fig.canvas.mpl_connect('pick_event', onpick)
show()
From: Trevis C. <t_...@mr...> - 2007年06月11日 20:27:28
>=20
> Hi Trevis,
>=20
> <snip>
>=20
> On 12/06/07, Trevis Crane <t_...@mr...> wrote:
> > So, I figured maybe if I zoomed in then it'd be easier to select the
desired
> > point. The problem is that after zooming/panning, the mouse cursor
changes
> > and my click events are no longer recognized as such. Furthermore,
I can't
> > find a way to make the mouse cursor return to its normal state and
allow me
> > to continue clicking events. Is there something I'm missing?
>=20
> Could it be that you're still in zoom or pan mode when you try to
> click to select a point? You'll see the zoom or pan button highlighted
> in the toolbar if that is the case. Clicks when in these modes don't
> activate the callback feature, so you need to click again on the same
> toolbar button to leave that mode; then the cursor should return to an
> arrow and your callback routine should be activated correctly.
[Trevis Crane]=20
I feel like a bonehead sometimes. That helps. I didn't know to click
the button again to get out of pan/zoom mode.
thanks,
trevis
=20
> HTH,
>=20
> A.
> --
> AJC McMorland, PhD Student
> Physiology, University of Auckland
>=20
>
------------------------------------------------------------------------
-
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Richard A. <ral...@in...> - 2007年06月11日 20:26:54
try using plot_date() function instead of plot()
On Sun, 2007年06月10日 at 09:49 +0200, rolandreichel wrote:
> Hi,
> 
> I want to plot some timeseries (eg. stockcharts). I use now 
> DateLocator/Formatter, it works fine for me with the exeption, that 
> dataless periods on X-Axis (eg. weekends) are also plotted. Is there an 
> easy way to suppress them?
> 
> regards
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Angus M. <am...@gm...> - 2007年06月11日 20:25:29
Hi Trevis,
<snip>
On 12/06/07, Trevis Crane <t_...@mr...> wrote:
> So, I figured maybe if I zoomed in then it'd be easier to select the desired
> point. The problem is that after zooming/panning, the mouse cursor changes
> and my click events are no longer recognized as such. Furthermore, I can't
> find a way to make the mouse cursor return to its normal state and allow me
> to continue clicking events. Is there something I'm missing?
Could it be that you're still in zoom or pan mode when you try to
click to select a point? You'll see the zoom or pan button highlighted
in the toolbar if that is the case. Clicks when in these modes don't
activate the callback feature, so you need to click again on the same
toolbar button to leave that mode; then the cursor should return to an
arrow and your callback routine should be activated correctly.
HTH,
A.
-- 
AJC McMorland, PhD Student
Physiology, University of Auckland
From: Trevis C. <t_...@mr...> - 2007年06月11日 20:09:39
Hi,
=20
I've coded (with help from John) a plot of mine to allow a user to
select a data point, and when they click on it a new plot pops up. It
works great. However, some of the points are very close together and if
I'm not extremely careful in selecting the point, then multiple graphs
pop up or I get the wrong one entirely. =20
=20
So, I figured maybe if I zoomed in then it'd be easier to select the
desired point. The problem is that after zooming/panning, the mouse
cursor changes and my click events are no longer recognized as such.
Furthermore, I can't find a way to make the mouse cursor return to its
normal state and allow me to continue clicking events. Is there
something I'm missing?
=20
thanks,
trevis
=20
________________________________________________
=20
Trevis Crane
Postdoctoral Research Assoc.
Department of Physics
University of Ilinois
1110 W. Green St.
Urbana, IL 61801
=20
p: 217-244-8652
f: 217-244-2278
e: tc...@ui...
________________________________________________
=20
From: Roman B. <be...@sm...> - 2007年06月11日 15:40:21
* John Hunter <jd...@gm...> [070611 16:20]:
> So the answer of which is better is a question of skill level and
> context, but my simple advice is to use the pylab syntax from the
> interactive python shell (and "ipython -pylab" is ideal for this) and
> the API everywhere else. Most of my scripts are variants of this:
> 
> import numpy as npy
> from pylab import figure, close, show
> fig = figure()
> ax = fig.add_subplot(111)
> x = npy.arange(0,10.)
> ax.plot(x)
> show()
Hello,
is there also a (possible object oriented) way to show/print a given
figure? Like fig.show() or fig.print_figure(). I need it because I have
a script generating (returning) several plots, and the user should be
able to print/show the plots he likes. At the moment I use:
ipython -pylab
 from myscript import plotgenerator 
 fig = plotgenerator()
 canvas = get_current_fig_manager().canvas
 canvas.figure = fig
 canvas.print_figure('myplot.png')
Here plotgenerator does something like:
 from matplotlib.figure import Figure
 fig = Figure()
 ax = myplot.add_subplot(111)
 ax.plot(x)
But its cumbersome, and canvas.show() doesn not work (it gives an
exception). Best would be if fig.show() (popping up a new canvas) and
fig.print_figure() worked.
Best Regards, Roman
From: Rutkov D. <den...@ma...> - 2007年06月11日 15:02:17
Hello everyone! I'm seeking help with real-time plotting using Python and MatPlotLib. I've encoutered several problems so far:
1. There is no function to just add a point to the existing curve, so each time the data is updated all the curve has to be redrawn. This is not a clean solution for the real-time plotting.
2. I'm trying to use threads in Python in order to be able to get the data and draw the curve at the same time. Sometimes it's working, and sometimes the graphics rendering just hangs. Moreover, if I try to use the Timer class for the plotting thread, it is invoked only one time. I wonder, if my threads are stirring with a graphical library ones. If there is no special thread handling with Tk, I'll investigate my code again.
I'll appreciate any help.
Thank you.
Dendron.
P.S.: Sorry, forgot to put a title in the previous post.
From: Rutkov D. <den...@ma...> - 2007年06月11日 14:34:55
Hello everyone! I'm seeking help with real-time plotting using Python and MatPlotLib. I've encoutered several problems so far:
1. There is no function to just add a point to the existing curve, so each time the data is updated all the curve has to be redrawn. This is not a clean solution for the real-time plotting. 
2. I'm trying to use threads in Python in order to be able to get the data and draw the curve at the same time. Sometimes it's working, and sometimes the graphics rendering just hangs. Moreover, if I try to use the Timer class for the plotting thread, it is invoked only one time. I wonder, if my threads are stirring with a graphical library ones. If there is no special thread handling with Tk, I'll investigate my code again.
I'll appreciate any help.
Thank you.
Dendron.
From: Sam V. <vo...@gm...> - 2007年06月11日 14:23:49
Sorry for the repost, but I'm still struggling with this.
I'm trying to replicate a plot like this:
http://tinyurl.com/2uwjn8
In this case, the y-axis on the left (the black dots) is linear
and the y-axis on the right (red data) is log base 2.
I can't figure out how to do the following:
1. How do I display the right-hand y-axis so that is includes the
range above 32 and below 0 (as in the linked figure)? When I try to
include 0 or below in the
axis range, I get a range error (because of the log function). When I
do auto-range, it ranges from 2 to 32. But I want to include 0 (and
below) in my figure.
2. How do I line up the centers of both axes. in this case, the y-axis
on the left needs to have the 0 value lined up with the value of 2 on
the y axis on the right. In other words, how to I move one y-axis
relative to the other.
This is the best I can do so far.
http://tinyurl.com/yotf2b
As you can see, I can't get the right axis as log2 and still keep the
0 values. I'd really like to have a log axis on the right, because
some of those values (red) are quite high.
Thanks for the advice.
From: Trevis C. <t_...@mr...> - 2007年06月11日 14:13:36
> -----Original Message-----
> From: John Hunter [mailto:jd...@gm...]
> Sent: Monday, June 11, 2007 9:08 AM
> To: Trevis Crane
> Cc: mat...@li...
> Subject: Re: [Matplotlib-users] out of curiosity...
>=20
> On 6/11/07, Trevis Crane <t_...@mr...> wrote:
>=20
> > Coming from MATLAB, I started using matplotlib in the same fashion
(and was
> > very appreciative of the similariry). That is, I would import pylab
and
> > call the plotting functions as necessary. However, after seeing
some of how
> > others are using matplotlib, it seems most people use axes object
methods to
> > take care of plotting needs. I'm now taking this approach as well,
but I
> > honestly don't know why I should (or if I should). Will someone
explain to
> > me why one approach is better or worse?
>
[Trevis Crane]=20
John, your explanation is great. Thanks for taking the time.
trevis
> matplotlib supports both because in different contexts one is often
> superior to the other.
>=20
> The main difference is that the pylab interface is stateful and
> handles object instantiation when necessary. For example, when you do
> "plot", it checks to see if there is a current axes and if so plots
> into it, and if not creates a new axes. When the new axes function is
> called, it checks to see if there is a current figure and inserts into
> it if available, and if not creates one. So it is "stateful" because
> under the hood it is tracking the current axes, figure and some other
> stuff.
>=20
> When working interactively from the shell or in short scripts, this is
> a nice feature because it saves typing and syntactic overhead. When
> working in the shell, eg in ipython -pyab mode, this is usually the
> way I work.
>=20
> In other contexts the convenience that these functions imply become a
> liability, because you often want to have explicit control, eg "put
> this axes in this figure and put this plot into this axes...". In a
> web application server or a user interface application, this is
> definitely the way to work. In scripts of moderate complexity it is
> advisable.
>=20
> The basic idea is that "explicit is better than implicit". Working
> this way is a little harder at first, but by forcing yourself to
> understand who is doing what where, you ultimately write better, more
> stable, more maintainable code.
>=20
> One thing most serious python programmers agree on is that
>=20
> from something import *
>=20
> is bad practice because you usually don't know what names are coming
> from where, and it creates the possibility of latent bugs. Eg, pylab
> used to have a "set" command which emulates the matlab command of the
> same name. It is used to set handle graphics properties. This worked
> fine, until python introduced the "set" builtin, which works like the
> mathematical set. Then it became impossible do "from pylab import *"
> and use the new python builtin "set", so we cleaned up all the old
> code and renamed the function. The programmer who do
>=20
> import pylab
> pylab.set
>=20
> was protected from these often subtle and difficult to detect bugs.
>=20
> The import * idiom also makes it tricky to combine code from two
> scripts or modules into one, because both may be importing different
> namespaces with overlapping names.
>=20
> I have found, however, when talking to science teachers who are trying
> to introduce python/numpy/pylab/scipy into the classroom as a matlab
> replacement that the 'from pylab import *' idiom is important to them,
> because their students want something that "just works" and is about
> as easy as matlab. Even though it is probably preferable in the
> abstract to teach students good practices from the beginning, it might
> raise the barrier to entry sufficiently that they simply use matlab
> instead. These teachers are already facing a fair amount of
> resistance in trying to get python introduced at all, and we should
> make it as easy on them as possible. So I am not a zealot on this
> issue.
>=20
> The other reason it is good practice to use the explicit API calls is
> that code which starts out its life as a small script often has a way
> of growing into a large script, and then you begin sharing it with
> your colleagues and maybe writing a web interface or a GUI application
> built on it. Code written using the API can safely be dropped into
> larger applications, whereas code written in pylab probably cannot
> (imagine lots of different functions competing for the current figure
> w/o knowledge of one another).
>=20
> So the answer of which is better is a question of skill level and
> context, but my simple advice is to use the pylab syntax from the
> interactive python shell (and "ipython -pylab" is ideal for this) and
> the API everywhere else. Most of my scripts are variants of this:
>=20
> import numpy as npy
> from pylab import figure, close, show
> fig =3D figure()
> ax =3D fig.add_subplot(111)
> x =3D npy.arange(0,10.)
> ax.plot(x)
> show()
>=20
> JDH
From: John H. <jd...@gm...> - 2007年06月11日 14:08:06
On 6/11/07, Trevis Crane <t_...@mr...> wrote:
> Coming from MATLAB, I started using matplotlib in the same fashion (and was
> very appreciative of the similariry). That is, I would import pylab and
> call the plotting functions as necessary. However, after seeing some of how
> others are using matplotlib, it seems most people use axes object methods to
> take care of plotting needs. I'm now taking this approach as well, but I
> honestly don't know why I should (or if I should). Will someone explain to
> me why one approach is better or worse?
matplotlib supports both because in different contexts one is often
superior to the other.
The main difference is that the pylab interface is stateful and
handles object instantiation when necessary. For example, when you do
"plot", it checks to see if there is a current axes and if so plots
into it, and if not creates a new axes. When the new axes function is
called, it checks to see if there is a current figure and inserts into
it if available, and if not creates one. So it is "stateful" because
under the hood it is tracking the current axes, figure and some other
stuff.
When working interactively from the shell or in short scripts, this is
a nice feature because it saves typing and syntactic overhead. When
working in the shell, eg in ipython -pyab mode, this is usually the
way I work.
In other contexts the convenience that these functions imply become a
liability, because you often want to have explicit control, eg "put
this axes in this figure and put this plot into this axes...". In a
web application server or a user interface application, this is
definitely the way to work. In scripts of moderate complexity it is
advisable.
The basic idea is that "explicit is better than implicit". Working
this way is a little harder at first, but by forcing yourself to
understand who is doing what where, you ultimately write better, more
stable, more maintainable code.
One thing most serious python programmers agree on is that
 from something import *
is bad practice because you usually don't know what names are coming
from where, and it creates the possibility of latent bugs. Eg, pylab
used to have a "set" command which emulates the matlab command of the
same name. It is used to set handle graphics properties. This worked
fine, until python introduced the "set" builtin, which works like the
mathematical set. Then it became impossible do "from pylab import *"
and use the new python builtin "set", so we cleaned up all the old
code and renamed the function. The programmer who do
import pylab
pylab.set
was protected from these often subtle and difficult to detect bugs.
The import * idiom also makes it tricky to combine code from two
scripts or modules into one, because both may be importing different
namespaces with overlapping names.
I have found, however, when talking to science teachers who are trying
to introduce python/numpy/pylab/scipy into the classroom as a matlab
replacement that the 'from pylab import *' idiom is important to them,
because their students want something that "just works" and is about
as easy as matlab. Even though it is probably preferable in the
abstract to teach students good practices from the beginning, it might
raise the barrier to entry sufficiently that they simply use matlab
instead. These teachers are already facing a fair amount of
resistance in trying to get python introduced at all, and we should
make it as easy on them as possible. So I am not a zealot on this
issue.
The other reason it is good practice to use the explicit API calls is
that code which starts out its life as a small script often has a way
of growing into a large script, and then you begin sharing it with
your colleagues and maybe writing a web interface or a GUI application
built on it. Code written using the API can safely be dropped into
larger applications, whereas code written in pylab probably cannot
(imagine lots of different functions competing for the current figure
w/o knowledge of one another).
So the answer of which is better is a question of skill level and
context, but my simple advice is to use the pylab syntax from the
interactive python shell (and "ipython -pylab" is ideal for this) and
the API everywhere else. Most of my scripts are variants of this:
 import numpy as npy
 from pylab import figure, close, show
 fig = figure()
 ax = fig.add_subplot(111)
 x = npy.arange(0,10.)
 ax.plot(x)
 show()
JDH
From: Trevis C. <t_...@mr...> - 2007年06月11日 13:39:42
Coming from MATLAB, I started using matplotlib in the same fashion (and
was very appreciative of the similariry). That is, I would import pylab
and call the plotting functions as necessary. However, after seeing
some of how others are using matplotlib, it seems most people use axes
object methods to take care of plotting needs. I'm now taking this
approach as well, but I honestly don't know why I should (or if I
should). Will someone explain to me why one approach is better or worse?
=20
thanks,
trevis
=20
________________________________________________
=20
Trevis Crane
Postdoctoral Research Assoc.
Department of Physics
University of Ilinois
1110 W. Green St.
Urbana, IL 61801
=20
p: 217-244-8652
f: 217-244-2278
e: tc...@ui...
________________________________________________
=20
From: __ <red...@gm...> - 2007年06月11日 13:08:06
Excellent. Thank you very much!
On 6/10/07, Jake Emerson <jak...@on...> wrote:
>
> The python imaging library is pretty good for this kind of thing.
>
> http://www.pythonware.com/library/pil/handbook/
>
> Here's an (untested) example. Hope it helps.
>
> Jake
>
>
> #!/usr/bin/env python
>
> from pylab import scatter, save
> import Image
>
> #get the background image, and find out how big it is
> im_bg = Image.open("background.png")
> bg_width, bg_height = im.size
>
> #make a white canvas on which to paste the background image and the
> scatter plot
> #this will allow you to, say, have the x- and y-axis values fall outside
> of the background image's limits
> im_canvas = Image.new("RGBA", (bg_width+60, bg_height+60), (255, 255, 255,
> 0))
>
> #create the scatter plot from x and y data with matplotlib
> scatter(x, y, s=sizes, alpha=0.75)
>
> #save the scatter plot, and then retrieve it for use in PIL, convert to
> RGBA so that alpha levels will work
> #there is probably a better way to do this with gcf() or gci()...
> savefig("scatter_plot.png")
> im_scatter = Image.open("scatter_plot.png").convert("RGBA")
>
> #resize the scatter image to make it fit nice
> im_scatter.resize((bg_width+10, bg_height+10))
>
> #bring all of the images together by pasting them onto the white canvas,
> use the overlayed image as the mask (third element)
> im_canvas.paste(im_bg, (30, 30), im_bg) #play around
> with the paste locations (30, 30)
> im_canvas.paste(im_scatter, (10, 30), im_scatter) #these won't be
> perfect the first time (10, 30)
>
> #save it
> im_canvas.save("combo_image.png")
>
>
>
>
> ------------------------------
> *From:* __ [mailto:red...@gm...]
> *Sent:* Sunday, June 10, 2007 5:22 PM
> *To:* mat...@li...
> *Subject:* [Matplotlib-users] Simple scatter plot over an image
>
> Hello,
>
> I'm trying to plot a simple list of x/y coords over an image (.png). I can
> show the image, or plot the data, but cannot find a way to layer one over
> the other. I would greatly appreciate someone pointing me in the right
> direction. Thanks.
>
From: John H. <jd...@gm...> - 2007年06月11日 12:33:00
On 6/10/07, __ <red...@gm...> wrote:
> Hello,
>
> I'm trying to plot a simple list of x/y coords over an image (.png). I can
> show the image, or plot the data, but cannot find a way to layer one over
> the other. I would greatly appreciate someone pointing me in the right
Just call imshow and set the "extent" kwarg to let mpl know about the
coordinates of the image, and then call scatter. See
examples/image_demo2.py in the mpl src distribution, ot at
http://matplotlib.sourceforge.net/examples/image_demo2.py
JDH
From: fred <fr...@gm...> - 2007年06月11日 10:35:16
Attachments: essai.py
Hi,
Please look at the short example attached showing the issue.
I want to display only one contour line, with value 0.8.
Obviously, the color associated with this contour line is bad
(blue instead of red color).
I think the reason is that the contour has its own colormap,
so for only one value, the color is blue.
I don't see anything about this issue in the contour help.
How can I fix this ?
Thanks in advance.
Cheers,
-- 
http://scipy.org/FredericPetit
From: Eric F. <ef...@ha...> - 2007年06月11日 07:37:10
nappie74 wrote:
> 
> 
> nappie74 wrote:
>> Hi,
>> I'm new in matplolib code,
>> I have matrix of winds vectors 
> 
> Hi, thanks, yes infact wind barbs it's difficult to plot with quiver I have
> to coding something appropiate.
> So ,just I HAVE FOR THE MOMENT TO PLOT ONLY A LEGEND with one wind vector
> that have a lenght autoscaled like quiver: this vector is for example 5 m/s
> and for the other vectors everyone can make an idea of intensity. the legend
> facilty make this or is there an other way in quiver commands.
> --Pie
> 
In the mpl examples directory look at quiver_demo.py, which illustrates 
the quiverkey function.
Eric
From: Matthias M. <Mat...@gm...> - 2007年06月11日 07:26:17
Hello darkside,
the below example seems to do the job. 
The problem with x, y = event.xdata, event.ydata could be due to a 
local-global-variable issue (solution: define x, y with keyword global, 
i.e. "global x, y" in your function 'click' [ -> they become global 
variables] to change their values in this function and use them in the main 
program, too).
best regards,
Matthias
>----------------------------------------------------------------------------------------------------------
import pylab
from matplotlib.widgets import Cursor
datax=[]
datay =[]
def click(event):
 if event.button == 1:
 if event.inaxes:
 print 'data coords: ', event.xdata, event.ydata
 datax.append(event.xdata)
 datay.append(event.ydata)
 # disconnect the connection with id 'cid' after the first run of
 # this part
 pylab.disconnect(cid)
 if event.button == 3:
 # only possible before the first run of the upper 
 # part ' if event.button == 1'
 pylab.close()
 return datax,datay
fig = pylab.figure(figsize=(8,6))
ax = fig.add_subplot(111)
ax.plot(pylab.arange(10))
cursor = Cursor(ax, useblit=False, color='red', linewidth=2)
cursor.horizOn = False
# connection with id 'cid'
cid = pylab.connect('button_press_event', click)
pylab.show()
print 'los arrays de data son: ', datax,datay
>-----------------------------------------------------------------------------------------------------
On Sunday 10 June 2007 04:54, darkside wrote:
> Hello,
> I've tried your idea, but it doesn't work.
> If I put:
> ----------------------
> datax=[]
> datay =[]
>
>
> def click(event):
>
> if event.button == 1:
> if event.inaxes:
> print 'data coords: ', event.xdata, event.ydata
> datax.append(event.xdata)
> datay.append(event.ydata)
> pylab.disconnect(click)
>
> if event.button == 3:
> pylab.close()
>
> return datax,datay
>
> fig = pylab.figure(figsize=(8,6))
> ax = fig.add_subplot(111)
> ax.plot(pylab.arange(10))
> cursor = Cursor(ax, useblit=False, color='red', linewidth=2)
> cursor.horizOn = False
>
> pylab.connect('button_press_event', click)
>
> pylab.show()
> print 'los arrays de data son: ', datax,datay
> ------------------------
> It returns the arrays, but it doesn't stop after one click, I have to press
> number 3 to exit.
>
> I tried to change to x, y instead of datax, datay in the following way:
>
> ------------------------
> x, y = 0,0
>
> x, y = event.x, event.y
> -----------------------------
>
> But in this case I get an error: "name 'x' is not defined"
> And I don't know why, because I only change the lines refering to datax,
> datay. It seems that only works with lists, but I don't know if this is the
> problem exactly.
>
> With the command close, I can close the figure window pressing right mouse
> button. It works (at least something works).
>
> Thank you for your help.
>
> 2007年6月4日, Matthias Michler <Mat...@gm...>:
> > Hello darkside,
> >
> > maybe the following little examples helps you with disconnecting:
> > >------------------------------------------------------------------------
> > >--------
> >
> > from pylab import *
> >
> > def event_response(event):
> > print event.name
> > disconnect(cid)
> >
> > subplot(111)
> > cid = connect('button_press_event', event_response)
> >
> > show()
> >
> > >------------------------------------------------------------------------
> > >-----
> >
> > concerning opening of figures:
> > I think it is not possible to open a figure after the show()
> > ( I asked some time ago with subject "open / close or set active figures
> > during mainloop", but unfortunately without response).
> >
> > Maybe it would be sufficient for you to clean the figure or the axes
> > (pylab.clf/cla), resetting labels and use the same connected event
> > several times.
> >
> > best regards,
> > Matthias
> >
> > On Monday 04 June 2007 04:28, darkside wrote:
> > > I'm trying to use matplotlib to get an x point on some figures by
> >
> > mouse
> >
> > > clicking.
> > > To do this I try the next example:
> > > -------------------------
> > > datax=[]
> > > datay =[]
> > > def click(event):
> > > x, y = event.x, event.y
> > > if event.button == 1:
> > > if event.inaxes:
> > > print 'data coords: ', event.xdata, event.ydata
> > > datax.append(event.xdata)
> > > datay.append(event.ydata)
> > > if event.button == 3:
> > > pylab.close()
> > > return datax,datay
> > > fig = pylab.figure(figsize=(8,6))
> > > ax = fig.add_subplot(111)
> > >
> > > - Ignored:
> > > ax.plot(pylab.arange(10))
> > > cursor = Cursor(ax, useblit=False, color='red', linewidth=2)
> > > cursor.horizOn = False
> > >
> > > pylab.connect('button_press_event', click)
> > >
> > > pylab.show()
> > > pylab.disconnect(click)
> > > print 'los arrays de data son: ', datax,datay
> > > ------------------------------------------------------
> > >
> > > My problem is tha I want to only be able to click each figure once,
> >
> > then
> >
> > > lock the
> > > figure (making it unclickable), close it and open another one. But
> >
> > I'm
> >
> > > not
> > > able to
> > > implement this.
> > > Anyone have any suggestions?.
> >
> > -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: nappie74 <nap...@ti...> - 2007年06月11日 07:22:49
nappie74 wrote:
> Hi,
> I'm new in matplolib code,
> I have matrix of winds vectors 
Hi, thanks, yes infact wind barbs it's difficult to plot with quiver I have
to coding something appropiate.
So ,just I HAVE FOR THE MOMENT TO PLOT ONLY A LEGEND with one wind vector
that have a lenght autoscaled like quiver: this vector is for example 5 m/s
and for the other vectors everyone can make an idea of intensity. the legend
facilty make this or is there an other way in quiver commands.
--Pie
-- 
View this message in context: http://www.nabble.com/to-build-barbs-in-quiver-resultant-vector-tf3889736.html#a11056084
Sent from the matplotlib - users mailing list archive at Nabble.com.
From: Mark B. <ma...@gm...> - 2007年06月11日 07:07:20
Works for me.
Thanks, Mark
On 6/11/07, Eric Firing <ef...@ha...> wrote:
>
> Mark,
>
> Presumably the mailing list method worked at one time, but it would be
> obscure and unintuitive even if it worked now. There are no other
> explicit dash styles given as a pair of numbers in the rc file, so the
> change I made in svn is to use the strings "solid" and "dashed"; the
> two-float specification is deprecated.
>
> Eric
>
> Mark Bakker wrote:
> > Hello -
> >
> > I tried to turn of the feature that makes contours with negative values
> > dashed.
> > According to the mailinglist this should go by setting:
> > rcParams['contour.negative_linestyle']=('None','None')
> > I tried any combination of the None, None syntax, or just 'solid', but
> > nothing worked.
> > Example shown below. I am using 0.90.1.
> > Thanks, Mark
> >
> > from pylab import *
> > x,y = meshgrid(linspace(-3,3,10),linspace(-3,3,10))
> > rcParams['contour.negative_linestyle']=('None','None')
> > contour(x,y,x,colors='b')
> >
> > Error message:
> >
> > Traceback (most recent call last):
> > File "<pyshell#10>", line 1, in ?
> > contour(x,y,x,colors='b')
> > File "C:\Python24\Lib\site-packages\matplotlib\pylab.py", line 1777,
> > in contour
> > draw_if_interactive()
> > File
> > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py",
> > line 59, in draw_if_interactive
> > figManager.show()
> > File
> > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py",
> > line 311, in show
> > self.canvas.draw()
> > File
> > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py",
> > line 154, in draw
> > FigureCanvasAgg.draw(self)
> > File
> > "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line
> > 392, in draw
> > self.figure.draw(renderer)
> > File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 601,
> > in draw
> > for a in self.axes: a.draw(renderer)
> > File "C:\Python24\Lib\site-packages\matplotlib\axes.py", line 1286, in
> > draw
> > a.draw(renderer)
> > File "C:\Python24\Lib\site-packages\matplotlib\collections.py", line
> > 700, in draw
> > transoffset)
> > ValueError: invalid literal for float(): None
> >
> >
> > ------------------------------------------------------------------------
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > Mat...@li...
> > https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Jake E. <jak...@on...> - 2007年06月11日 03:10:18
The python imaging library is pretty good for this kind of thing.
=20
http://www.pythonware.com/library/pil/handbook/
=20
Here's an (untested) example. Hope it helps.
=20
Jake
=20
=20
#!/usr/bin/env python
=20
from pylab import scatter, save
import Image
=20
#get the background image, and find out how big it is
im_bg =3D Image.open("background.png")
bg_width, bg_height =3D im.size
=20
#make a white canvas on which to paste the background image and the
scatter plot
#this will allow you to, say, have the x- and y-axis values fall outside
of the background image's limits
im_canvas =3D Image.new("RGBA", (bg_width+60, bg_height+60), (255, 255,
255, 0))
=20
#create the scatter plot from x and y data with matplotlib
scatter(x, y, s=3Dsizes, alpha=3D0.75)
=20
#save the scatter plot, and then retrieve it for use in PIL, convert to
RGBA so that alpha levels will work
#there is probably a better way to do this with gcf() or gci()...
savefig("scatter_plot.png")
im_scatter =3D Image.open("scatter_plot.png").convert("RGBA")
=20
#resize the scatter image to make it fit nice
im_scatter.resize((bg_width+10, bg_height+10))
=20
#bring all of the images together by pasting them onto the white canvas,
use the overlayed image as the mask (third element)
im_canvas.paste(im_bg, (30, 30), im_bg) #play around
with the paste locations (30, 30)
im_canvas.paste(im_scatter, (10, 30), im_scatter) #these won't be
perfect the first time (10, 30)
=20
#save it
im_canvas.save("combo_image.png")
=20
=20
=20
=20
________________________________
From: __ [mailto:red...@gm...]=20
Sent: Sunday, June 10, 2007 5:22 PM
To: mat...@li...
Subject: [Matplotlib-users] Simple scatter plot over an image
Hello,=20
I'm trying to plot a simple list of x/y coords over an image (.png). I
can show the image, or plot the data, but cannot find a way to layer one
over the other. I would greatly appreciate someone pointing me in the
right direction. Thanks.=20
From: Eric F. <ef...@ha...> - 2007年06月11日 00:41:26
Mark,
Presumably the mailing list method worked at one time, but it would be 
obscure and unintuitive even if it worked now. There are no other 
explicit dash styles given as a pair of numbers in the rc file, so the 
change I made in svn is to use the strings "solid" and "dashed"; the 
two-float specification is deprecated.
Eric
Mark Bakker wrote:
> Hello -
> 
> I tried to turn of the feature that makes contours with negative values 
> dashed.
> According to the mailinglist this should go by setting: 
> rcParams['contour.negative_linestyle']=('None','None')
> I tried any combination of the None, None syntax, or just 'solid', but 
> nothing worked.
> Example shown below. I am using 0.90.1.
> Thanks, Mark
> 
> from pylab import *
> x,y = meshgrid(linspace(-3,3,10),linspace(-3,3,10))
> rcParams['contour.negative_linestyle']=('None','None')
> contour(x,y,x,colors='b')
> 
> Error message:
> 
> Traceback (most recent call last):
> File "<pyshell#10>", line 1, in ?
> contour(x,y,x,colors='b')
> File "C:\Python24\Lib\site-packages\matplotlib\pylab.py", line 1777, 
> in contour
> draw_if_interactive()
> File 
> "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", 
> line 59, in draw_if_interactive
> figManager.show()
> File 
> "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", 
> line 311, in show
> self.canvas.draw()
> File 
> "C:\Python24\Lib\site-packages\matplotlib\backends\backend_tkagg.py", 
> line 154, in draw
> FigureCanvasAgg.draw(self)
> File 
> "C:\Python24\Lib\site-packages\matplotlib\backends\backend_agg.py", line 
> 392, in draw
> self.figure.draw(renderer)
> File "C:\Python24\Lib\site-packages\matplotlib\figure.py", line 601, 
> in draw
> for a in self.axes: a.draw(renderer)
> File "C:\Python24\Lib\site-packages\matplotlib\axes.py", line 1286, in 
> draw
> a.draw(renderer)
> File "C:\Python24\Lib\site-packages\matplotlib\collections.py", line 
> 700, in draw
> transoffset)
> ValueError: invalid literal for float(): None
> 
> 
> ------------------------------------------------------------------------
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Showing 23 results of 23

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