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






Showing 8 results of 8

From: Peter G. <pgr...@ge...> - 2004年10月14日 23:45:41
John Hunter wrote:
>>>>>>"Peter" == Peter Groszkowski <pgr...@ge...> writes:
>>>>>>
>
> >> also in 0.60.2 i noticed that ticker.DayMultiLocator is used
> >> on line 1518 of matplotlib/axes.py but is not imported
>
> Peter> That was just after DayMultiLocator was added; it's a
> Peter> bug. You can just add it yourself. I use (a little
> Peter> modified) 60.2 as well on two production servers. It seems
> Peter> very stable at this point. Great majority of my plotting
> Peter> uses plot_date and with the new changes (haven't tried -
> Peter> just read about) I am afraid that lots of my code will
> Peter> break. So might take this opportunity to ask:
>
>My apologies for the hassle. 
>
No need. Evolution...
> I suspect you'll find the conversion
>painless when/if you can ever work yourself up to it. I converted all
>the datetime example code in a matter of minutes
>
> 1) convert your epoch to proleptic gregorian dates(see below)
>
> 2) remove the converter instance from the calls to plot_date
>
> 3) check your tick locator constructors replacing all 'base'
> constructors with explicit constructors (expect for the
> YearLocator, which still take the base arg). Eg if you want even
> months, do MonthLocator(range(2,13,2)) rather than MonthLocator(2)
>
>
sounds straight forward..
>
>import matplotlib.numerix as nx
>from matplotlib.dates import num2date
>
>def epoch2num(e):
> spd = 24.*3600.
> return 719163 + nx.asarray(e)/spd 
>
>e = range(0,20000,1000)
>d = epoch2num(e)
>
>print num2date(d[0])
>
>If everyone is happy with the conversion function name and
>implementation, I'll add it to the dates module.
>
epoch2num() looks good to me.. i usually deal with large data sets 
(often >500k points) and the conversion still seems very quick with 
Numeric. Will try to upgrade within next couple of weeks.
Thanks
Peter
P.S So when can we see your daughter join the matplotlib development? 
Judging from your usual responses to our questions/requests, I bet it's 
sometime real soon.
-- 
Peter Groszkowski Gemini Observatory
Tel: +1 808 974-2509 670 N. A'ohoku Place
Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA
From: John H. <jdh...@ac...> - 2004年10月14日 20:10:37
>>>>> "Peter" == Peter Groszkowski <pgr...@ge...> writes:
 >> also in 0.60.2 i noticed that ticker.DayMultiLocator is used
 >> on line 1518 of matplotlib/axes.py but is not imported
 Peter> That was just after DayMultiLocator was added; it's a
 Peter> bug. You can just add it yourself. I use (a little
 Peter> modified) 60.2 as well on two production servers. It seems
 Peter> very stable at this point. Great majority of my plotting
 Peter> uses plot_date and with the new changes (haven't tried -
 Peter> just read about) I am afraid that lots of my code will
 Peter> break. So might take this opportunity to ask:
My apologies for the hassle. I suspect you'll find the conversion
painless when/if you can ever work yourself up to it. I converted all
the datetime example code in a matter of minutes
 1) convert your epoch to proleptic gregorian dates(see below)
 2) remove the converter instance from the calls to plot_date
 3) check your tick locator constructors replacing all 'base'
 constructors with explicit constructors (expect for the
 YearLocator, which still take the base arg). Eg if you want even
 months, do MonthLocator(range(2,13,2)) rather than MonthLocator(2)
 Peter> Does the new date plotting mechanism support the old way of
 Peter> using "seconds from epoch"? It was very efficient as a lot
 Peter> of data (not only mine I would imagine) is simply in that
 Peter> format.
I'll provide a converter func in the dates module. This is what I
think should be done, but I'll bounce it off the list to make sure.
Epoch time starts at 1970,1,1
 >>> time.gmtime(0) 
 (1970, 1, 1, 0, 0, 0, 3, 1, 0)
 >>> dt = datetime(1970, 1, 1, 0, 0, 0, tzinfo=None)
 >>> dt.toordinal()
 719163 
So to convert to the new calendar, add 719163 and divide by seconds
per day. Since you can do this in numerix, it shouldn't impose a
noticeable performance hit on your script
import matplotlib.numerix as nx
from matplotlib.dates import num2date
def epoch2num(e):
 spd = 24.*3600.
 return 719163 + nx.asarray(e)/spd 
e = range(0,20000,1000)
d = epoch2num(e)
print num2date(d[0])
If everyone is happy with the conversion function name and
implementation, I'll add it to the dates module.
JDH
From: Peter G. <pgr...@ge...> - 2004年10月14日 19:35:05
>
> also in 0.60.2 i noticed that ticker.DayMultiLocator is used on line 
> 1518 of matplotlib/axes.py but is not imported
That was just after DayMultiLocator was added; it's a bug. You can just 
add it yourself. 
I use (a little modified) 60.2 as well on two production servers. It 
seems very stable at this point. Great majority of my plotting uses 
plot_date and with the new changes (haven't tried - just read about) I 
am afraid that lots of my code will break. So might take this 
opportunity to ask:
Does the new date plotting mechanism support the old way of using 
"seconds from epoch"? It was very efficient as a lot of data (not only 
mine I would imagine) is simply in that format.
-- 
Peter Groszkowski Gemini Observatory
Tel: +1 808 974-2509 670 N. A'ohoku Place
Fax: +1 808 935-9235 Hilo, Hawai'i 96720, USA
From: John H. <jdh...@ac...> - 2004年10月14日 17:30:59
>>>>> "Moe" == Moe Aboulkheir <mo...@po...> writes:
 Moe> sorry i did not explain fully. due to the asynchronous
 Moe> nature of the twisted framework, most blocking operations are
 Moe> generally executed inside threads, or at least, they are in
 Moe> my case.
I figured as much.
 Moe> thank you, and indeed i am confused, however i am using
 Moe> matplotlib 0.60.2, and here is the method declaration for
 Moe> Figure's __init__ (from matplotlib/figure.py):
 Moe> also in 0.60.2 i noticed that ticker.DayMultiLocator is used
 Moe> on line 1518 of matplotlib/axes.py but is not imported
Both of these are fixed in the current matplotlib release. You may
want to consider upgrading, particularly if you are actively writing
date code, since the date handling has changed and it may be less
painful to upgrade sooner rather than later when you have a large code
base installed. See the release notes at what's new for matplotlib
0.63.
Also, *many* memory leaks have been fixed - for web applications, this
may be important.
 Moe> the example you sent looks to be most helpful, thanks for
 Moe> taking the time to help me out.
 Moe> Moe
From: Jean-Michel P. <jea...@ir...> - 2004年10月14日 17:26:10
Attachments: coords.py
Hello,
I recently worked on displaying plot coordinates from the example code 
'coord_demo.py' so that I now have a script that should provide the 
following features:
 - coords are displayed either when clicking a mouse button or when 
stopping the mouse cursor in the plot for a given time (based on a timer)
 - coords can be displayed in the console or directly in the figure (a 
kind of balloon)
 - displayed coords are the nearest plot point coords provided the 
number of point distances to compute between mouse and curves is low 
enough to preserve resources, coords are only displayed if the smallest 
computed distance is "small" enough
 - coords displaying is activated by calling a unique function, its 
args define the type of event that triggers coords displaying and the 
callback that renders these coords (users can then provide their own one)
The callback that displays coords in a balloon uses the 'text' function 
of matplotlib.matlab such that this feature shouldn't rely on any backend.
Unfortunately things don't work for all backends. The results are the 
following:
		console displaying	balloon displaying
		------------------	------------------
WXAgg			OK			OK
TkAgg			OK			hangs
GTKAgg		nothing happens		nothing happens
Note that I never tried in an interactive session and I currently use 
matplotlib 0.62.4. In case some people are interested in having a look 
at my code, I attached it. This is a module that can be run as a 
standalone script for testing.
If things finally get work, I plan to add a backend-independent "cross 
hair" as 'wxcursor_demo.py' does using lines, and to highlight the 
nearest point in the figure by changing its color and/or its marker (but 
I still don't know how to!). I also wonder about the opportunity to add 
a toolbar button for this kind of tool. This would certainly require 
further improvements since my script seems to interact with the zoom 
tool callback while drawing the rectangle with the mouse. Moreover I 
only tested it for a single plot at the moment.
JM. Philippe
From: Moe A. <mo...@po...> - 2004年10月14日 16:30:46
John,
thanks for your very quick response.
> You may not be forced to do this; it depends on the circumstances.
> I've used the matlab interface to serve web pages before, though not
> with twisted. The use of the word global (in the example script
> pythonic_matplotlib) may not be the best choice, since the "globals"
> like the current figure and current axes are really module level
> variables that many modules access. But if you are creating figures
> in threads, this would be a problem. So the matplotlib API is a sound
> choice.
sorry i did not explain fully. due to the asynchronous nature of the 
twisted framework, most blocking operations are generally executed 
inside threads, or at least, they are in my case.
> I think you are confusing the figure linewidth with the plot
> linewidth. The Figure constructor does have a linewidth parameter in
> the __init__ method, though this is almost certainly not what you
> want. 
thank you, and indeed i am confused, however i am using matplotlib 
0.60.2, and here is the method declaration for Figure's __init__ (from 
matplotlib/figure.py):
class Figure(Artist):
 def __init__(self,
 figsize = None, # defaults to rc figure.figsize
 dpi = None, # defaults to rc figure.dpi
 facecolor = None, # defaults to rc figure.facecolor
 edgecolor = None, # defaults to rc figure.edgecolor
 frameon = True,
 ):
also in 0.60.2 i noticed that ticker.DayMultiLocator is used on line 
1518 of matplotlib/axes.py but is not imported
the example you sent looks to be most helpful, thanks for taking the 
time to help me out.
Moe
From: John H. <jdh...@ac...> - 2004年10月14日 14:41:46
>>>>> "Moe" == Moe Aboulkheir <mo...@po...> writes:
 Moe> Hey, i'm using matplotlib to create plots inside the twisted
 Moe> asynchronous web framework, so i am forced to use the
 Moe> pythonic API to avoid making global calls, however i have 3
 Moe> questions and would be extremely grateful if anyone could
 Moe> help me out.
You may not be forced to do this; it depends on the circumstances.
I've used the matlab interface to serve web pages before, though not
with twisted. The use of the word global (in the example script
pythonic_matplotlib) may not be the best choice, since the "globals"
like the current figure and current axes are really module level
variables that many modules access. But if you are creating figures
in threads, this would be a problem. So the matplotlib API is a sound
choice.
 Moe> 1) The online docs say that Figure.__init__ takes a linewidth
 Moe> keyword argument, but it does not. how can i set the
 Moe> linewidth for a figure, and how can i set the fontsize for a
I think you are confusing the figure linewidth with the plot
linewidth. The Figure constructor does have a linewidth parameter in
the __init__ method, though this is almost certainly not what you
want. This parameter controls the width of the line around the border
of the figure, a frame if you will, which is normally invisible
because the figure edge line and figure background color are both set
to white by default for saving figures. You are probably interested
in the lines.linewidth parameter which controls the default thickness
of all plot lines. This, and many more parameters, can be set in your
http://matplotlib.sf.net/.matplotlibrc file. You can also control the
default tick sizes, label sizes, colors, etc...
 Moe> figure, without doing weird things like map( lambda t:
 Moe> t.set_fontsize( 6 ), legend.get_texts() )
There are no default legend parameters in rc, so you'll have to
manually do it. You give up some of the convenience of the matlab
interface by using the api. Normally, one would use the matlab
interface 'set' command for this. In the example below, I include an
implementation of set called setapi that you may want to use in your
api code.
 Moe> 2) all of the examples using the pythonic API instantiate a
 Moe> Figure, and then do add_subplot(). this works for me, but
 Moe> matplotlib adds a bunch of space around the figure that i
 Moe> dont need. is there a way around this, or an alternative to
 Moe> add_subplot if i want only one plot?
Sure; use fig.add_axes. Then you can specify the left, bottom, width
and height of your axes as fractions of the entire figure size.
add_subplot is merely a convenience function to predefine some useful
axes sizes, but for full control, you'll want to set the axes size
yourself.
 Moe> 3) my ticklabels for the X axis happen to be quite lengthy
 Moe> strings, and they overlap if placed horizontally, adjacent to
 Moe> each other. i am using rotation = 45 but then a lot of the
 Moe> text gets clipped off of the bottom of the figure (im setting
 Moe> figsize in the Figure constructor). i am happy with the size
 Moe> of the figure, but would like more space for the text at the
 Moe> bottom.
Again, this is a problem with the default axes size. By making the
bottom a little higher, you can prevent your text from getting
clipped. The other option (you may want to do both) is use a smaller
fontsize for your tick labels.
 Moe> any help will be greatly appreciated. Moe Aboulkheir
Since there really was no true OO example for the agg backend, I wrote
one. It gives examples of how to solve all the problems you
encountered - this is examples/webapp_demo.py in CVS.
#!/usr/bin/env python
# This example shows how to use the agg backend directly to create
# images, which may be of use to web application developers who want
# full control over their code without using the matlab interface to
# manage figures, figure closing etc.
#
# I am making no effort here to make a figure that looks good --
# rather I am just trying to show the various ways to use matplotlib
# to customize your figure using the matplotlib API
import matplotlib
matplotlib.use('Agg') # force the antigrain backend
from matplotlib import rc
from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.figure import Figure
from matplotlib.cbook import iterable
import matplotlib.numerix as nx
# Set some properties that affect the defaults of all figures. The rc
# command is used to create per-script default figure customizations
# of the rc parameters; see http://matplotlib.sf.net/.matplotlibrc .
# You may prefer to set the rc parameters in the rc file itself. Note
# that you can keep directory level default configurations by placing
# different rc files in the directory that the script runs in.
rc('lines', linewidth=2) # thicker plot lines
rc('grid', color=0.75, linestyle='-') # solid gray grid lines
rc('axes', hold=True, # hold state is on
 grid=True, facecolor='y') # yellow background, grid on
rc('tick', color='r', labelsize=20) # big red ticks
def setapi(o, **kwargs):
 """
 for all key, value pairs in kwargs, and all objects in (possibly)
 iterable o, look for a method o.set_key and try to call
 o.set_key(value) if it exists. This is basically a refinition of
 the matlab interface set command
 """
 if not iterable(o): o = [o]
 for thiso in o: # iterate over the objects
 for k,v in kwargs.items():
 func = getattr(thiso, 'set_'+k)
 if func is None: continue
 func(v)
def make_fig():
 """
 make a figure
 No need to close figures or clean up since the objects will be
 destroyed when they go out of scope
 """
 fig = Figure()
 #ax = fig.add_subplot(111) # add a standard subplot
 # add an axes at left, bottom, width, height; by making the bottom
 # at 0.3, we save some extra room for tick labels
 ax = fig.add_axes([0.2, 0.3, 0.7, 0.6])
 line, = ax.plot([1,2,3], 'ro--', markersize=12, markerfacecolor='g')
 # make a translucent scatter collection 
 x = nx.rand(100)
 y = nx.rand(100)
 area = nx.pi*(10 * nx.rand(100))**2 # 0 to 10 point radiuses
 c = ax.scatter(x,y,area)
 c.set_alpha(0.5) 
 # add some text decoration
 ax.set_title('My first image')
 ax.set_ylabel('Some numbers') 
 ax.set_xticks( (.2,.4,.6,.8) )
 labels = ax.set_xticklabels(('Bill', 'Fred', 'Ted', 'Ed'))
 # To set object properties, you can either iterate over the
 # objects manually, or define you own set command, as in setapi
 # above.
 #setapi(labels, rotation=45, fontsize=12)
 for l in labels:
 l.set_rotation(45)
 l.set_fontsize(12)
 
 canvas = FigureCanvasAgg(fig)
 canvas.print_figure('webapp.png', dpi=150)
make_fig()
From: Moe A. <mo...@po...> - 2004年10月14日 10:23:00
Hey,
i'm using matplotlib to create plots inside the twisted asynchronous web 
framework, so i am forced to use the pythonic API to avoid making global 
calls, however i have 3 questions and would be extremely grateful if 
anyone could help me out.
1) The online docs say that Figure.__init__ takes a linewidth keyword 
argument, but it does not. how can i set the linewidth for a figure, 
and how can i set the fontsize for a figure, without doing weird things like
map( lambda t: t.set_fontsize( 6 ), legend.get_texts() )
2) all of the examples using the pythonic API instantiate a Figure, and 
then do add_subplot(). this works for me, but matplotlib adds a bunch 
of space around the figure that i dont need. is there a way around 
this, or an alternative to add_subplot if i want only one plot?
3) my ticklabels for the X axis happen to be quite lengthy strings, and 
they overlap if placed horizontally, adjacent to each other. i am using 
rotation = 45 but then a lot of the text gets clipped off of the bottom 
of the figure (im setting figsize in the Figure constructor). i am 
happy with the size of the figure, but would like more space for the 
text at the bottom.
any help will be greatly appreciated.
Moe Aboulkheir

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