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


Showing 13 results of 13

From: Skip M. <sk...@po...> - 2010年09月29日 20:43:49
I have a GTK app which runs its matplotlib stuff in a separate
thread. If I call pylab.show() at the end of building the plot
the first time it displays, then after that I have to destroy
the window before it will think about plotting something else,
and it never does (it pretends to - my log message tell me that
it is). If I call pylab.draw() no window is ever displayed. My
GUI is always active.
I would like to pop up a new top-level window for each figure.
How do I do that? My current build-a-plot code looks like this:
 figure = pylab.figure()
 ax = figure.add_subplot(111)
 ax.yaxis.set_major_formatter(pylab.FormatStrFormatter('%.7f'))
 ... build dates and prices lists ...
 ax.plot(dates, prices)
 formatter = matplotlib.dates.DateFormatter('%H:%M:%S')
 ax.xaxis.set_major_formatter(formatter)
 figure.autofmt_xdate()
 ... what goes here? ...
Instead of show() or draw() as the last line what should I be
doing?
Thx,
Skip Montanaro
From: Russell E. O. <ro...@uw...> - 2010年09月29日 19:09:24
I finished my strip chart widget thanks to help from Tony S Yu, Benjamin 
Root and others here. It supports multiple subplots and multiple 
lines/subplot. Here's a copy if anyone is interested:
<http://www.astro.washington.edu/users/rowen/python/StripChartWdg.py>
I plan to add it to the RO python package once I have tested it a bit 
more. Meanwhile, the example code at the end uses a prerelease RO module 
that I've also uploaded: 
<http://www.astro.washington.edu/users/rowen/python/RandomWalk.py>
It uses the TkAgg back end, but is easily ported (as usual, event timing 
is the main issue; I wish Python had its own event model that all GUIs 
could use).
I think I finally got the animation API figured out well enough to 
produce a robust result. Strip charts are intrinsically poor candidates 
for the animation API because the time axis is constantly shifting, but 
nonetheless animation does produce a small reduction in CPU usage.
Any feedback would be most welcome.
Regards,
-- Russell
From: Justin M. <jn...@gm...> - 2010年09月29日 17:49:14
Not to pile on the "auto-adjust to make labels fit" bandwagon, but
I've been following the FAQ on adjusting the subplot locations to make
room for too-long tick labels:
 http://matplotlib.sourceforge.net/faq/howto_faq.html#automatically-make-room-for-tick-labels
and have found that the FAQ code isn't very robust.
For example, if I interactively change the size of the plotting window
so the ylabels touch the left hand side of the window, stretching it
right again pushes the labels and the subplots too far to the right
(see attached 'auto_subplot_adjust.toofar.png').
If I make the window too narrow so the figure itself shrinks too much,
it starts to raise 'ValueError: left cannot be >= right' exceptions,
and then really shrinks the plot even more (see attached
'auto_subplot_adjust.leftright.png').
Any suggestions for making this more robust?
 Justin
From: Joe K. <jki...@wi...> - 2010年09月29日 17:05:00
If you're just looking for the dimensions of the overall figure in pixels,
you can easily access them through other means. E.g:
import matplotlib.pyplot as plt
fig = plt.figure()
_, _, width, height = fig.bbox.extents # <- Extent of the figure in pixels
fig.savefig('temp.png', dpi=fig.dpi) # <- Be sure to specify the dpi!!
Note that you'll have to specify that you want to save the figure at the
same DPI it was when you called the extents...
The figure will be saved with whatever default DPI is in your .matplotlibrc,
which is commonly different than the default screen dpi (80).
Hope that helps,
-Joe
On Wed, Sep 29, 2010 at 9:44 AM, Alexander Dietz <
ale...@go...> wrote:
> Hi,
>
> On Wed, Sep 29, 2010 at 16:00, John Hunter <jd...@gm...> wrote:
>
>> On Wed, Sep 29, 2010 at 8:50 AM, Alexander Dietz
>> <Ale...@go...> wrote:
>>
>> > print ax.transData.transform((10.0, 20.0))
>> > [ 576. 432.]
>>
>>
>> Why do you say it's wrong? Note that in mpl, (0,0) is (bottom left),
>> not (upper,left). So this is saying that the yellow dot at 10,20
>> (data coords) is 576 pixels up from the bottom and 432 pixels over
>> from the left.
>>
>
>
> ok maybe it is. But then I need the size of the entire figure written to a
> file. How can I find out the pixel-size of the entire figure, inclusive
> every title, axis, labels...
>
>
> Thanks
> Alex
>
>
>
>>
>> JDH
>>
>
>
>
> ------------------------------------------------------------------------------
> Start uncovering the many advantages of virtual appliances
> and start using them to simplify application deployment and
> accelerate your shift to cloud computing.
> http://p.sf.net/sfu/novell-sfdev2dev
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
From: Sebastian R. <seb...@go...> - 2010年09月29日 17:02:14
Hi all,
if I plot an normal figure the toolbar contains an button (looks like a
checkbox), which can be used to edit the lines and axes parameters. But when
I embed such a figure in an Wx application, this specfic button is missing.
Is there a way around it?
Thanks for your help,
Sebi
Parts of the Code:
import wx
import os
import numpy as np
import wx.grid
import filtertools as ft
# Matplotlib Figure object
from matplotlib.figure import Figure
# import the WxAgg FigureCanvas object, that binds Figure to
# WxAgg backend --> a wxPanel
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as
FigureCanvas
# import the NavigationToolbar WxAgg widget
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
....
class MplPanel(wx.Panel):
 def __init__(self, *args, **kwds):
 wx.Panel.__init__(self, *args, **kwds)
 self.__set_properties()
 self.__do_layout()
 self.figure = Figure(figsize=(sizex, sizey), dpi=res)
 self.axes = self.figure.add_subplot(111)
 self.axes.set_xticks(np.arange(self.xmin_limit, self.xmax_limit,
 20))
 self.axes.set_yticks(np.arange(self.ymin, self.ymax, 0.1));
 self.axes.axis([self.xmin,self.xmax,self.ymin,self.ymax])
 self.axes.grid(True)
 self.axes.set_xlabel('Wavelength [nm]',fontsize=14)
 self.axes.set_ylabel('Transmission [%] or Intensity
[a.u.]',fontsize=14)
 self.figure.subplots_adjust(left=0.07, bottom=0.09, right=0.97,
top=0.94,wspace=0.20, hspace=0.20)
 self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
 self.sizer = wx.BoxSizer(wx.VERTICAL)
 self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
 self.toolbar = NavigationToolbar2Wx(self.canvas)
 self.toolbar.Realize()
 self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
 self.toolbar.Show()
 self.SetSizer(self.sizer)
 self.Fit()
...
-- 
Dr. Sebastian Rhode
Grünwalder Str. 103a
81547 München
Tel: +49 89 4703091
Mobil: +49 15122810945
seb...@go...
From: Alexander D. <ale...@go...> - 2010年09月29日 14:44:39
Hi,
On Wed, Sep 29, 2010 at 16:00, John Hunter <jd...@gm...> wrote:
> On Wed, Sep 29, 2010 at 8:50 AM, Alexander Dietz
> <Ale...@go...> wrote:
>
> > print ax.transData.transform((10.0, 20.0))
> > [ 576. 432.]
>
>
> Why do you say it's wrong? Note that in mpl, (0,0) is (bottom left),
> not (upper,left). So this is saying that the yellow dot at 10,20
> (data coords) is 576 pixels up from the bottom and 432 pixels over
> from the left.
>
ok maybe it is. But then I need the size of the entire figure written to a
file. How can I find out the pixel-size of the entire figure, inclusive
every title, axis, labels...
Thanks
 Alex
>
> JDH
>
From: Benjamin R. <ben...@ou...> - 2010年09月29日 14:24:46
On Wed, Sep 29, 2010 at 4:21 AM, Ruggero <giu...@gm...> wrote:
> I'm using matplotlib 0.9, is there a best way to do this:
>
>
> for labeltick in ax.xaxis.get_majorticklabels() +
> ax.yaxis.get_majorticklabels():
> labeltick.set_fontsize(15)
>
>
> I can't do:
> ax.tick_params(labelsize=15) as here:
>
> http://matplotlib.sourceforge.net/api/axes_api.html?highlight=ticklabel_format#matplotlib.axes.Axes.tick_params
>
> is it a new feature?
>
>
Yes, this is a new feature for v1.0.0 because setting parameters for ticks
have been so difficult and confusing in the past. The way you have it right
now for version 0.9 is the "correct" way to do it for that version.
Ben Root
From: Benjamin R. <ben...@ou...> - 2010年09月29日 14:22:36
On Tue, Sep 28, 2010 at 10:56 PM, Philip Vetter
<pv+...@ma...<pv%2Bm...@ma...>
> wrote:
> Hello! see below for sample code.
>
> (1) I find that the second subplot is shifted to the right.
> This seems to happen generally with colorbar. How do I fix it?
>
> (2) is there a way to clear/remove selected parts of the figure?
> I am using ipython for interactive figure drawing
> I find clf() will erase everything, cla() will empty the square plot,
> but I can't see how to clear the first subfigure or the colorbar.
> This would be useful as any changes to the colorbar create a new one.
> (uncomment the second cbar line to see this)
>
> (3) is it possible to modify the orientation of cbar once drawn?
> cbar.orientation ='horizontal'
> plt.draw()
> plt.show()
> leaves it unchanged.
>
> Thank you for your help!
>
> ================ Here is my code: ==================
>
> #!/usr/bin/env python
> import matplotlib.pyplot as plt
> import numpy as np
> from time import sleep
> x = np.arange(0, 10, 0.2)
> y = np.sin(x)
> fig = plt.figure()
> ax1 = fig.add_subplot(211)
> cax1 = ax1.plot(x, y)
> ax2 = fig.add_subplot(212)
> A = np.random.random_integers(0, 10, 100).reshape(10, 10)
> cax2 = ax2.imshow(A, interpolation="nearest",vmin=-1,vmax=11 )
> cbar = fig.colorbar(cax2)
> #cbar = fig.colorbar(cax2, ticks=[0, 5, 10])
> plt.savefig('colorbartest.pdf')
>
> ======================================================
> --
>
>
Philip,
Typically, when creating a colorbar, matplotlib "steals" some space from a
particular axes. This is fine for single plots, but it looks atrocious when
doing subplots. Instead, what you want is axes_grid1
http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/
(note, if you have a version earlier than 1.0.0, then it is called
"axes_grid" and it is a little bit different)
With this, you can specify a bunch of layout options ahead of time and get
an object with all of the axes you need. In particular, I think you want to
look at
http://matplotlib.sourceforge.net/plot_directive/mpl_toolkits/axes_grid/examples/demo_axes_grid.py
A quick note to clear up typical confusion in that demo... You can still use
subplots and embed an AxesGrid within a subplot region (although, I find
this unnecessary). For this reason, the linked demo has three subplots in a
single figure, and each of those subplots have four subplots. Therefore,
when creating each AxesGrid, one needs to specify the subplot coordinates
such as 131, 132, 133, but you can simply use 111 if you want AxesGrid to
handle all of your subplotting.
To address one of your other questions, you can easily specify the
orientation of your colorbar to be horizontal or vertical.
I hope that helps!
Ben Root
From: Jonathan S. <js...@cf...> - 2010年09月29日 14:12:46
This is interesting. It seems that the event.x, event.y values are for
the entire figure area rather than limited to the image. Anyone know
how to get the image values instead?
Also, I wonder how one might get the values of the pixels (i.e. image
value) at the pixels that you click on. One more thing -- is there a
way to make the cursor be a full plot window cross -- graphically like:
	 ------------------
 | | |
 | | |
 | | |
 |--------|---------|
 | | |
 | | |
 ------------------
It makes it easier to align with the axes sometimes (the IDL astronomy
library has a routine called rdplot that does this).
Jon
From: John H. <jd...@gm...> - 2010年09月29日 14:00:40
On Wed, Sep 29, 2010 at 8:50 AM, Alexander Dietz
<Ale...@go...> wrote:
> print ax.transData.transform((10.0, 20.0))
> [ 576. 432.]
Why do you say it's wrong? Note that in mpl, (0,0) is (bottom left),
not (upper,left). So this is saying that the yellow dot at 10,20
(data coords) is 576 pixels up from the bottom and 432 pixels over
from the left.
JDH
From: John H. <jd...@gm...> - 2010年09月29日 13:40:11
On Wed, Sep 29, 2010 at 4:44 AM, Alexander Dietz
<ale...@go...> wrote:
> I would like to know how to find out the extend of the actual image in a
> plot, in units of pixels.
> As example I have attached a plot which is essentially empty. The lower left
> corner is indicated by a red dot - what pixel position does this location
> have? When opening this image in e.g. kview it is easy to find out that this
> left corner of the actual plot corresponds to pixel (100,540). And so the
> upper right corner (the yellow dot) is (720,60).
>
> But how do I find out these coordinates when generating such a plot with
> matplotlib? Are there some variables of the axis or the actual plot that
> contain these numbers?
Take a look at the transformations tutorial.
 http://matplotlib.sourceforge.net/users/transforms_tutorial.html
To convert from data -> pixel coordinates, use the axes transData transformation
 In [1]: ax = gca()
 In [2]: ax.transData.transform((0.5, 0.5))
 Out[2]: array([ 333.125, 245. ])
You can also use mpl events to inspect the coordinates of the point
under the mouse
In [3]: fig = gcf()
In [4]: def on_click(event):
 ...: print event.x, event.y
 ...:
 ...:
In [5]: cid = fig.canvas.mpl_connect('button_press_event', on_click)
In [6]: 188 166.0
300 227.0
384 292.0
In [7]: fig.canvas.mpl_disconnect(cid)
See http://matplotlib.sourceforge.net/users/event_handling.html for more info.
JDH
From: Ruggero <giu...@gm...> - 2010年09月29日 09:22:01
I'm using matplotlib 0.9, is there a best way to do this:
 for labeltick in ax.xaxis.get_majorticklabels() +
ax.yaxis.get_majorticklabels():
 labeltick.set_fontsize(15)
I can't do:
ax.tick_params(labelsize=15) as here:
http://matplotlib.sourceforge.net/api/axes_api.html?highlight=ticklabel_format#matplotlib.axes.Axes.tick_params
is it a new feature?
From: Philip V. <pv+...@ma...> - 2010年09月29日 04:34:43
Hello! see below for sample code.
(1) I find that the second subplot is shifted to the right.
This seems to happen generally with colorbar. How do I fix it?
(2) is there a way to clear/remove selected parts of the figure?
I am using ipython for interactive figure drawing
I find clf() will erase everything, cla() will empty the square plot,
 but I can't see how to clear the first subfigure or the colorbar.
This would be useful as any changes to the colorbar create a new one.
(uncomment the second cbar line to see this)
(3) is it possible to modify the orientation of cbar once drawn?
cbar.orientation ='horizontal'
plt.draw()
plt.show()
leaves it unchanged.
Thank you for your help!
================ Here is my code: ==================
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
from time import sleep
x = np.arange(0, 10, 0.2)
y = np.sin(x)
fig = plt.figure()
ax1 = fig.add_subplot(211)
cax1 = ax1.plot(x, y)
ax2 = fig.add_subplot(212)
A = np.random.random_integers(0, 10, 100).reshape(10, 10)
cax2 = ax2.imshow(A, interpolation="nearest",vmin=-1,vmax=11 )
cbar = fig.colorbar(cax2)
#cbar = fig.colorbar(cax2, ticks=[0, 5, 10])
plt.savefig('colorbartest.pdf')
======================================================
-- 
2 messages has been excluded from this view by a project administrator.

Showing 13 results of 13

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