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

Showing 12 results of 12

From: <sk...@po...> - 2005年09月14日 22:54:53
 John> I'm not ready to give up just yet; I hate to leave pesky bugs
 John> unsquashed. Did you get a chance to try the PS and Agg tests I
 John> suggested above? 
Nope, I forgot about them. Thanks for the reminder.
 >> python myscript.py -dGTKAgg
Core dump, as before.
 >> python myscript.py -dGTK
Works with some complainst about fonts: 
 ** (myscript.py:8466): WARNING **: Couldn't load font "Bitstream Vera
 Sans, normal, 13" falling back to "Sans 13"
 >> python myscript.py -dPS
Works.
 >> python myscript.py -dAgg
Works.
 John> Also, if you get a chance to make the debug build I suggested
 John> earlier with VERBOSE=True and could send the output my way, that
 John> would help.
I'll try to remember to give that a try tomorrow.
Thanks for your persistence...
Skip
From: John H. <jdh...@ac...> - 2005年09月14日 22:38:10
>>>>> "skip" == skip <sk...@po...> writes:
 Fernando> So unless you end up needing to embed mpl into GTK apps
 Fernando> ...
 skip> That was precisely my thought... Even if we only get it
 skip> working with Tk, we'll at least have a much better tool than
 skip> GNUplot.
I'm not ready to give up just yet; I hate to leave pesky bugs
unsquashed. Did you get a chance to try the PS and Agg tests I
suggested above? I'm assuming since the TkAgg backend worked these
will too. It would help narrow the bug to know which of these
commands work on the canonical script
from pylab import plot, savefig, show
plot([1,2,3])
savefig('test')
show()
 > python myscript.py -dGTKAgg
 > python myscript.py -dGTK
 > python myscript.py -dPS
 > python myscript.py -dAgg
In particular, it would be nice to know if GTK and GTKAgg are both
broken, or just GTKAgg.
Also, if you get a chance to make the debug build I suggested earlier
with VERBOSE=True and could send the output my way, that would help.
Thanks,
JDH
From: <sk...@po...> - 2005年09月14日 22:25:30
 Fernando> So unless you end up needing to embed mpl into GTK apps ...
That was precisely my thought... Even if we only get it working with Tk,
we'll at least have a much better tool than GNUplot.
Skip
From: Fernando P. <Fer...@co...> - 2005年09月14日 21:10:09
sk...@po... wrote:
> >> Any simpler suggestions?
> 
> Fernando> Can you use TkAgg as your backend (set it in
> Fernando> ~/.matplotlib/matplotlibrc)? 
> 
> Thanks for the suggestion. To be honest, I'd never even considered Tk since
> we're a Gtk shop. That worked in both interactive and batch (well, at least
> the simple first example from the tutorial worked). That narrows my problem
> space down to Gtk and PyGtk. I suspect I could have guessed the problem was
> in the Gtk space without performing any tests though...
Good. Most likely, everything will work. I use TkAgg for all my stuff, and 
it's fine. Even if you get GTK to build, it won't mean you're out of the 
woods. John and I have been trying, unsuccessfully, to track down a very 
bizarre GTK-only crash. Since ipython plays thread tricks to make an 
interactive console coexist happily with the gtk event mainloop, it's bound to 
be a more brittle setup than plain old Tk.
So unless you end up needing to embed mpl into GTK apps or have a burning 
desire to spend the weekend in the company of Electric Fence and gdb, Tk might 
just be enough.
Cheers,
f
From: <sk...@po...> - 2005年09月14日 21:02:36
 >> Any simpler suggestions?
 Fernando> Can you use TkAgg as your backend (set it in
 Fernando> ~/.matplotlib/matplotlibrc)? 
Thanks for the suggestion. To be honest, I'd never even considered Tk since
we're a Gtk shop. That worked in both interactive and batch (well, at least
the simple first example from the tutorial worked). That narrows my problem
space down to Gtk and PyGtk. I suspect I could have guessed the problem was
in the Gtk space without performing any tests though...
 Fernando> Even if you need GTK/WX, you may want to test with Tk just to
 Fernando> see what happens, before pulling the heavy artillery out.
Granted.
Skip
From: John H. <jdh...@ac...> - 2005年09月14日 18:03:26
>>>>> "skip" == skip <sk...@po...> writes:
One more comment. I doubt this is the src of your woes, but don't do
this:
 import pygtk
 pygtk.require('2.6')
 import gtk
 from pylab import *
 plot([1,2,3,4])
 show()
 gtk.main()
You can either use matplotlib in GUI / API mode (eg
examples/embedding_in_gtk*.py) or in pylab mode, which hides the GUI.
"show", for example, starts the mainloop, so you don't want to call
show and gtk.main.
FYI, it is a common complaint that the OO interface is not as well
documented as the pylab interface. The classdocs are pretty good
though, and there are plenty of examples in the examples dir. Robert
Leftwich also provides this tutorial
 http://matplotlib.sf.net/leftwich_tut.txt
Assuming of course you can stop the thing from segfaulting :-(
From: John H. <jdh...@ac...> - 2005年09月14日 17:56:19
>>>>> "skip" == skip <sk...@po...> writes:
 skip> It would appear something else is going on here other than
 skip> straightforward issues of whether or not I'm running
 skip> interactively. Unfortunately, the wild differences between
 skip> the two gdb backtraces suggest that I'm going to have to
 skip> drag out Electric Fence or some other malloc debugger to
 skip> figure out what's wrong (oh joy, oh happy thought...), which
 skip> I don't have time for at the moment.
 skip> Any simpler suggestions?
Arggg. Sorry you are having so much trouble.
Two suggestions: try running different backends with a minimal script
 from pylab import plot, savefig
 plot([1,2,3])
 savefig('test')
run from the command line with
 > python myscript.py -dPS --verbose-helpful
 > python myscript.py -dAgg --verbose-helpful
and see if you get segfaults on both or either of the postscript and
agg pure image backends (taking gtk and attendant complexities out of
the loop). The --verbose-helpful information will be useful to post.
Also run with --verbose-debug which produces lots of extra
information like which fonts are being loaded etc. I have seen some
fonts which have crashed the mpl extension code, and I've tried to fix
these bugs when I find them.
If none of this is enlightening, do 
 > sudo rm -rf build /your/path/to/site-packages/matplotlib
and toggle the VERBOSE flag to True in setup.py and rebuild/reinstall.
This will cause the extension code to spew lots of extra debug
information, and usually helps narrow the locus of the bad code.
Let me know...
JDH
From: Fernando P. <Fer...@co...> - 2005年09月14日 17:53:15
sk...@po... wrote:
[ pain and suffering with gdb and EE menacingly lurking on the horizon ]
> Any simpler suggestions?
Can you use TkAgg as your backend (set it in ~/.matplotlib/matplotlibrc)? 
Personally I don't use any of the threaded backends, but just plain old Tk. 
While not as flashy as the others, it has the advantage of being very stable, 
allowing Ctrl-C to interrupt long-running computations, and letting me use 
other Tk-based apps I need.
Even if you need GTK/WX, you may want to test with Tk just to see what 
happens, before pulling the heavy artillery out.
Further, note that in ipython -pylab, you can type:
run myscript.py
and it will run your script (it's basically a wrapper around execfile() with 
fancy namespace hacks and control of matplotlib's rendering loop).
Let us know how that goes, I'll try to help as well.
Cheers,
f
From: <sk...@po...> - 2005年09月14日 17:46:08
 John> The problem here is that "show" starts the GUI mainloop when using
 John> a GUI backend (GTKAgg is the default)....
 John> The recommended approach for using the GTK/WX/Qt backends
 John> interactively from the shell is to use the ipython shell.
 John> Eg, you can do
 >> ipython -pylab
 John> Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
 John> Type "copyright", "credits" or "license" for more information.
 John> In [1]: hist(randn(10000), 100)
 John> and your plot should appear automagically.
Thanks for the continued help. I installed ipython 0.6.15 and the default
matplotlibrc. Ipython needed one tweak to the matplotlib import (it was
looking for matplotlib.matlab and matplotlib.pylab, but not
matplotlib.mlab). Your interactive hist(...) example also segfaults.
I tried a simple script:
 import pygtk
 pygtk.require('2.6')
 import gtk
 from pylab import *
 plot([1,2,3,4])
 show()
 gtk.main()
run in batch. That also segfaults. The gdb backtrace was massive. I gave
up looking after 600+ frames had been displayed and resorted to pystack
instead:
 (gdb) pystack
 /opt/lang/python/lib/python2.3/site-packages/matplotlib/backends/backend_gtk.py (611): _init_toolbar2_4
 /opt/lang/python/lib/python2.3/site-packages/matplotlib/backends/backend_gtk.py (567): _init_toolbar
 /opt/lang/python/lib/python2.3/site-packages/matplotlib/backend_bases.py (971): __init__
 /opt/lang/python/lib/python2.3/site-packages/matplotlib/backends/backend_gtk.py (507): __init__
 Previous frame inner to this frame (corrupt stack?)
Reducing my simple script to just
 from pylab import *
 plot([1,2,3,4])
 show()
yields another segfault, with this minimalist backtrace:
 (gdb) bt
 #0 0xd0cf29fc in strlen () from /lib/libc.so.1
 #1 0xd0d47e3e in _ndoprnt () from /lib/libc.so.1
 #2 0xd0d4af3b in vsnprintf () from /lib/libc.so.1
 #3 0xcf8e9cda in g_printf_string_upper_bound () from /usr/lib/libglib-2.0.so.0
It would appear something else is going on here other than straightforward
issues of whether or not I'm running interactively. Unfortunately, the wild
differences between the two gdb backtraces suggest that I'm going to have to
drag out Electric Fence or some other malloc debugger to figure out what's
wrong (oh joy, oh happy thought...), which I don't have time for at the
moment.
Any simpler suggestions?
Skip
From: John H. <jdh...@ac...> - 2005年09月14日 13:25:58
>>>>> "Martin" == Martin Richter <law...@gm...> writes:
 Martin> Hello everyone, Hello John,
 Martin> thank you very much for your example - it is really
 Martin> fantastic. This was exactly what I meant.
 Martin> When I was trying to rewrite your code to a
 Martin> 'fastplot()'-command (which would just be able to plot one
 Martin> point at a time) it worked quite well with the
 Martin> Circle()-command you used. But is there a possibility to
 Martin> write the 'fastplot' in a way so that it can be used like
 Martin> fastplot(x,y, marker='s', color='g',markersize = 3)?
This approach can work, but may not be as fast as possible since there
is more machinery in Line2D than you need (eg the sequence stuff, the
optional linestyle) and logically what you are doing is creating a
polygon. One option would be to create a polygon factory function or
class which parses a marker string and creates the Polygon instance
you want for your marker. You could lift the logic from Line2D, eg
 markerd = {
 . : _make_point,
 , : _make_pixel,
 o : _make_circle, 
 v : _make_triangle_down,
 ...snip
 }
where, for example _make_triangle_down is a stripped down version of
matplotlib.lines.Line2D._draw_triangle_down
 def _make_triangle_down(size):
 return ( (-size, size),
 (size, size),
 (0, -size))
you could then create the polygon as I did in my original example code
# this is just a sketch and not complete code, eg you will want to
# compute size appropriately as in the previous example
def polygon_factory(marker, **kwargs) 
 func = markerd[marker]
 verts = func(size)
 trans = identity_transform()
 trans.set_offset( (x, y), ax.transData)
 poly = Polygon( verts, transform=trans, **kwargs )
 poly.set_clip_box(ax.bbox)
 return poly
You could then use this function like
poly = polygon_factory('s', facecolor='blue', linewidth=2)
If you wanted full parsing of matplotlib format strings (eg 'go' for
green circle) which includes both color and marker, you can use
matplotlib.axes._process_plot_format or a variant of it.
 Martin> In the example given below the color is not recognized
 Martin> correctly. Do I use Line2D in a wrong way?
Line2D has both an a linestyle and a marker (eg you can pcreate a
single line instance which is 'ro--' (red dashed line with circle
markers). "color" and "linewidth" control the linestyle properties.
"markerfacecolor, ""markeredgecolor", and "markeredgewidth" control
the marker properties. Again, this illustrates why a Line2D object is
a bit too heavy for your needs. The polygon factory function would be
a useful addition to matplotlib.
 Martin> A second question aims on the running-behavior: It - well
 Martin> - stumbles a little bit. If you add a print i to the
 Martin> for-loop you can see that the counting is done very
 Martin> smoothly. But the plot isn't (at least at my computer -
 Martin> maybe this is already the answer).
As I've pointed out before (eg at the animation wiki
http://www.scipy.org/wikis/topical_software/Animations), the pylab
animation technique is for simple throw-away animations. To produce
nice animations, you need to use your GUI timer or idle function
handling. Eg, if I remove your ion, ioff calls and replace your
update functionality with
 def update(*args):
 i = update.cnt
 fastplot_points( x[i], y[i],marker='s',color='r')
 update.cnt +=1
 if update.cnt<1000: return True
 else: return False
 update.cnt = 0
 tend = time.time()
 print 'It took %4.2f s.'%(tend - tstart)
 import gobject
 gobject.idle_add(update)
 show()
The "jerky" update problem you describe goes away.
JDH
From: John H. <jdh...@ac...> - 2005年09月14日 12:44:27
>>>>> "Jeff" == Jeff Peery <jef...@se...> writes:
 Jeff> DateLocator((max-min)/8.0)
 ...snip...
 Jeff> Does anyone know what might be the problem with the
 Jeff> datelocator() as I've done it?
If you look at the documentation for the DateLocator
 http://matplotlib.sourceforge.net/matplotlib.dates.html#DateLocator
you'll see that it takes a single argument in the init function which
is a timezone. You are passing it (min-max)/8.0 which in my guess
does not evaluate to a timezone unless you are deep into overload
magic <wink>
DateLocator is base class and you will need to instantiate one of the
derived classes (eg MonthLocator). What plot_date does is inspect the
date range and try to make an intelligent guess about which kind of
locator you need. I just factored this code into a reusable date
locator/formatter factory function which is in CVS
 Checking in lib/matplotlib/dates.py;
 /cvsroot/matplotlib/matplotlib/lib/matplotlib/dates.py,v <-- dates.py
 new revision: 1.12; previous revision: 1.11
I'll post it here in case you don't have access to CVS and just want
to plug it into your application
import math
from matplotlib.dates import YearLocator, MonthLocator, WeekdayLocator, \
 DayLocator, HourLocator, MinuteLocator, DateFormatter
def date_ticker_factory(span, tz=None, numticks=5):
 """
 Create a date locator with numticks (approx) and a date formatter
 for span in days. Return value is (locator, formatter)
 """
 
 if span==0: span = 1/24.
 minutes = span*24*60
 hours = span*24
 days = span
 weeks = span/7.
 months = span/31. # approx
 years = span/365.
 if years>numticks:
 locator = YearLocator(int(years/numticks), tz=tz) # define
 fmt = '%Y'
 elif months>numticks:
 locator = MonthLocator(tz=tz)
 fmt = '%b %Y'
 elif weeks>numticks:
 locator = WeekdayLocator(tz=tz)
 fmt = '%a, %b %d'
 elif days>numticks:
 locator = DayLocator(interval=int(math.ceil(days/numticks)), tz=tz)
 fmt = '%b %d'
 elif hours>numticks:
 locator = HourLocator(interval=int(math.ceil(hours/numticks)), tz=tz)
 fmt = '%H:%M\n%b %d'
 elif minutes>numticks:
 locator = MinuteLocator(interval=int(math.ceil(minutes/numticks)), tz=tz)
 fmt = '%H:%M:%S'
 else:
 locator = MinuteLocator(tz=tz)
 fmt = '%H:%M:%S'
 formatter = DateFormatter(fmt, tz=tz)
 return locator, formatter
locator, formatter = date_ticker_factory(2000, numticks=8)
print locator, formatter
From: John H. <jdh...@ac...> - 2005年09月14日 12:26:54
>>>>> "skip" == skip <sk...@po...> writes:
 Skip> >>> plot([1,2,3,4])
 Skip> [<matplotlib.lines.Line2D instance at 0x8790d6c>]
 Skip> >>> show()
 Skip> (process:3261): GLib-GObject-CRITICAL **: gtype.c:2253: 
 Skip> initialization assertion failed, use g_type_init() prior to 
 Skip> this function
 Skip> Segmentation Fault (core dumped)
The problem here is that "show" starts the GUI mainloop when using a
GUI backend (GTKAgg is the default). To use the GTK, WX, or Qt
backends from a shell, you need to use a shell that starts the GUI
mainloop in a separate thread (Tkinter is special in this regard, in
that it can be use from the shell with no special threading calls, so
if you need to use the standard python shell for interactive work, you
should use the TkAgg backend). Also, you should not be using "show"
when working interactively from the shell. This is discussed in more
detail at
 http://matplotlib.sourceforge.net/interactive.html
and 
 http://matplotlib.sourceforge.net/faq.html#SHOW
The recommended approach for using the GTK/WX/Qt backends
interactively from the shell is to use the ipython shell. ipython is
an easy install (pure python) and in addition to lots of nice
interactive features, has matplotlib support. Specifically, in the
pylab mode
 > ipython -pylab
it will read your matplotlibrc file, detect your backend, issue the
proper threading and timer/idle calls as needed for GTK, WX, Qt or Tk,
import the pylab namespace and wash your dishes
 http://ipython.scipy.org
Eg, you can do
> ipython -pylab
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
Type "copyright", "credits" or "license" for more information.
In [1]: hist(randn(10000), 100)
and your plot should appear automagically.
If for some reason ipython is not an option for you, and you need to
use a GTK backend from the shell, there is some template code in the
matplotlib examples directory showing how to write a custom shell with
the proper gtk threading calls.
JDH

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