SourceForge logo
SourceForge logo
Menu

matplotlib-users — Discussion related to using matplotlib

You can subscribe to this list here.

2003 Jan
Feb
Mar
Apr
May
(3)
Jun
Jul
Aug
(12)
Sep
(12)
Oct
(56)
Nov
(65)
Dec
(37)
2004 Jan
(59)
Feb
(78)
Mar
(153)
Apr
(205)
May
(184)
Jun
(123)
Jul
(171)
Aug
(156)
Sep
(190)
Oct
(120)
Nov
(154)
Dec
(223)
2005 Jan
(184)
Feb
(267)
Mar
(214)
Apr
(286)
May
(320)
Jun
(299)
Jul
(348)
Aug
(283)
Sep
(355)
Oct
(293)
Nov
(232)
Dec
(203)
2006 Jan
(352)
Feb
(358)
Mar
(403)
Apr
(313)
May
(165)
Jun
(281)
Jul
(316)
Aug
(228)
Sep
(279)
Oct
(243)
Nov
(315)
Dec
(345)
2007 Jan
(260)
Feb
(323)
Mar
(340)
Apr
(319)
May
(290)
Jun
(296)
Jul
(221)
Aug
(292)
Sep
(242)
Oct
(248)
Nov
(242)
Dec
(332)
2008 Jan
(312)
Feb
(359)
Mar
(454)
Apr
(287)
May
(340)
Jun
(450)
Jul
(403)
Aug
(324)
Sep
(349)
Oct
(385)
Nov
(363)
Dec
(437)
2009 Jan
(500)
Feb
(301)
Mar
(409)
Apr
(486)
May
(545)
Jun
(391)
Jul
(518)
Aug
(497)
Sep
(492)
Oct
(429)
Nov
(357)
Dec
(310)
2010 Jan
(371)
Feb
(657)
Mar
(519)
Apr
(432)
May
(312)
Jun
(416)
Jul
(477)
Aug
(386)
Sep
(419)
Oct
(435)
Nov
(320)
Dec
(202)
2011 Jan
(321)
Feb
(413)
Mar
(299)
Apr
(215)
May
(284)
Jun
(203)
Jul
(207)
Aug
(314)
Sep
(321)
Oct
(259)
Nov
(347)
Dec
(209)
2012 Jan
(322)
Feb
(414)
Mar
(377)
Apr
(179)
May
(173)
Jun
(234)
Jul
(295)
Aug
(239)
Sep
(276)
Oct
(355)
Nov
(144)
Dec
(108)
2013 Jan
(170)
Feb
(89)
Mar
(204)
Apr
(133)
May
(142)
Jun
(89)
Jul
(160)
Aug
(180)
Sep
(69)
Oct
(136)
Nov
(83)
Dec
(32)
2014 Jan
(71)
Feb
(90)
Mar
(161)
Apr
(117)
May
(78)
Jun
(94)
Jul
(60)
Aug
(83)
Sep
(102)
Oct
(132)
Nov
(154)
Dec
(96)
2015 Jan
(45)
Feb
(138)
Mar
(176)
Apr
(132)
May
(119)
Jun
(124)
Jul
(77)
Aug
(31)
Sep
(34)
Oct
(22)
Nov
(23)
Dec
(9)
2016 Jan
(26)
Feb
(17)
Mar
(10)
Apr
(8)
May
(4)
Jun
(8)
Jul
(6)
Aug
(5)
Sep
(9)
Oct
(4)
Nov
Dec
2017 Jan
(5)
Feb
(7)
Mar
(1)
Apr
(5)
May
Jun
(3)
Jul
(6)
Aug
(1)
Sep
Oct
(2)
Nov
(1)
Dec
2018 Jan
Feb
Mar
Apr
(1)
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2020 Jan
Feb
Mar
Apr
May
(1)
Jun
Jul
Aug
Sep
Oct
Nov
Dec
2025 Jan
(1)
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
S M T W T F S






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





Showing 9 results of 9

From: fafcb <fas...@gm...> - 2010年05月07日 19:39:02
I'm new to matplotlib, so maybe this is obvious, but I've search quite a bit
and can't find the answer.
I have a data set with several hundred rows and about 5 columns. I want to
plot all data points (columns 2-5) on the same logarithmic chart with the x
axis showing calendar dates (column 1).
What is the best way to accomplish my task? I have been experimenting with
semilogy, but I can't seem to figure out how to get columns 2-5 to plot by
date. Just FYI, if it matters - the data is currently held in a csv file
and each column may or may not have a data point for each date.
Thanks in advance for any help!
From: Friedrich R. <fri...@gm...> - 2010年05月07日 19:06:44
2010年5月7日 Bartosz Telenczuk <bar...@gm...>:
> Dear all,
>
> I am working on figures for my thesis, which consist of several related
panels. Each of the panel contains several subplots. In order to arrange the
plots I would like to split the figure into two (or more) panels and within
each of them create a nested set of subplots. Optimally, the main panels
should define their own coordinate systems, such that all of the nested
subplot positions are defined within their frame. The syntax could look like
that:
>
> panel1 = subplot(1,2,1)
> panel2 = subplot(1,2,2)
>
> ax1 = panel1.add_subplot(1,2,1)
> ax2 = panel1.add_subplot(1,2,2)
>
> ax3 = panel2.add_subplot(111)
I think what you could maybe try is to write a class using figure.add_axes()
http://matplotlib.sourceforge.net/api/figure_api.html#matplotlib.figure.Figure.add_axes
The class could store a relative area and a "master". For the panels you
need, the master would be the Figure. Such a Panel class could expose an
add_axes() method too, but forwarding the call to its master. To calculate
the *rect* argument when callings its master's .add_axes(), it would use a
linear transformation from the stored extent to the (0, 1) extent relative
to the master. Let it be depicted:
+----------------------+ Figure
 +-------------+ Panel
 +------+ Axes
There could be more Panels in between. You would do:
>>> panel = Panel(figure, (0.2, 0.6)) # left = 0.2, width = 0.6, i.e. right
= 0.8
>>> axes = panel.add_axes((0, 0.5)) # left = 0, width = 0.5, i.e. right =
0.5
The last call would do:
1) Transform the (0, 0.5) to the Figure reference frame (more precise, to
the master ref frame, where by coincidence the Figure is the master). Thie
yields here (0.2, 0.3) = (left, width), i.e. right = 0.5 (in the master ref
frame).
2) Call master.add_axes((0.2, 0.3)). This actually creates the Axes
instance by recusions until the master is a Figure.
I think this approach is feasible in < 200 loc.
hth
Friedrich
From: John H. <jd...@gm...> - 2010年05月07日 18:22:58
On Fri, May 7, 2010 at 1:09 PM, Eric Firing <ef...@ha...> wrote:
> On 05/06/2010 08:02 PM, oyster wrote:
>> I know matplotlib mimics matlab, which offers scientific look.
>> but can we use matplotlib to get a skecth(in other words,
>> hand-drawing) style for bar/pie/etc in none formalist paper? for
>> example, http://teethgrinder.co.uk/open-flash-chart/gallery-bar-7.php
>> thanks
>
> With a considerable effort you could use mpl's capabilities to program
> this sort of thing, but it will not be added as an option.
JJ's demo_ribbon_box is pretty close -- you just need to create a base
image you want stretched to the bar height.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.image import BboxImage
from matplotlib._png import read_png
import matplotlib.colors
from matplotlib.cbook import get_sample_data
class RibbonBox(object):
 original_image = read_png(get_sample_data("Minduka_Present_Blue_Pack.png",
 asfileobj=False))
 cut_location = 70
 b_and_h = original_image[:,:,2]
 color = original_image[:,:,2] - original_image[:,:,0]
 alpha = original_image[:,:,3]
 nx = original_image.shape[1]
 def __init__(self, color):
 rgb = matplotlib.colors.colorConverter.to_rgb(color)
 im = np.empty(self.original_image.shape,
 self.original_image.dtype)
 im[:,:,:3] = self.b_and_h[:,:,np.newaxis]
 im[:,:,:3] -= self.color[:,:,np.newaxis]*(1.-np.array(rgb))
 im[:,:,3] = self.alpha
 self.im = im
 def get_stretched_image(self, stretch_factor):
 stretch_factor = max(stretch_factor, 1)
 ny, nx, nch = self.im.shape
 ny2 = int(ny*stretch_factor)
 stretched_image = np.empty((ny2, nx, nch),
 self.im.dtype)
 cut = self.im[self.cut_location,:,:]
 stretched_image[:,:,:] = cut
 stretched_image[:self.cut_location,:,:] = \
 self.im[:self.cut_location,:,:]
 stretched_image[-(ny-self.cut_location):,:,:] = \
 self.im[-(ny-self.cut_location):,:,:]
 self._cached_im = stretched_image
 return stretched_image
class RibbonBoxImage(BboxImage):
 zorder = 1
 def __init__(self, bbox, color,
 cmap = None,
 norm = None,
 interpolation=None,
 origin=None,
 filternorm=1,
 filterrad=4.0,
 resample = False,
 **kwargs
 ):
 BboxImage.__init__(self, bbox,
 cmap = cmap,
 norm = norm,
 interpolation=interpolation,
 origin=origin,
 filternorm=filternorm,
 filterrad=filterrad,
 resample = resample,
 **kwargs
 )
 self._ribbonbox = RibbonBox(color)
 self._cached_ny = None
 def draw(self, renderer, *args, **kwargs):
 bbox = self.get_window_extent(renderer)
 stretch_factor = bbox.height / bbox.width
 ny = int(stretch_factor*self._ribbonbox.nx)
 if self._cached_ny != ny:
 arr = self._ribbonbox.get_stretched_image(stretch_factor)
 self.set_array(arr)
 self._cached_ny = ny
 BboxImage.draw(self, renderer, *args, **kwargs)
if 1:
 from matplotlib.transforms import Bbox, TransformedBbox
 from matplotlib.ticker import ScalarFormatter
 fig = plt.gcf()
 fig.clf()
 ax = plt.subplot(111)
 years = np.arange(2004, 2009)
 box_colors = [(0.8, 0.2, 0.2),
 (0.2, 0.8, 0.2),
 (0.2, 0.2, 0.8),
 (0.7, 0.5, 0.8),
 (0.3, 0.8, 0.7),
 ]
 heights = np.random.random(years.shape) * 7000 + 3000
 fmt = ScalarFormatter(useOffset=False)
 ax.xaxis.set_major_formatter(fmt)
 for year, h, bc in zip(years, heights, box_colors):
 bbox0 = Bbox.from_extents(year-0.4, 0., year+0.4, h)
 bbox = TransformedBbox(bbox0, ax.transData)
 rb_patch = RibbonBoxImage(bbox, bc, interpolation="bicubic")
 ax.add_artist(rb_patch)
 ax.annotate(r"%d" % (int(h/100.)*100),
 (year, h), va="bottom", ha="center")
 patch_gradient = BboxImage(ax.bbox,
 interpolation="bicubic",
 zorder=0.1,
 )
 gradient = np.zeros((2, 2, 4), dtype=np.float)
 gradient[:,:,:3] = [1, 1, 0.]
 gradient[:,:,3] = [[0.1, 0.3],[0.3, 0.5]] # alpha channel
 patch_gradient.set_array(gradient)
 ax.add_artist(patch_gradient)
 ax.set_xlim(years[0]-0.5, years[-1]+0.5)
 ax.set_ylim(0, 10000)
 fig.savefig('ribbon_box.png')
 plt.show()
From: Eric F. <ef...@ha...> - 2010年05月07日 18:09:21
On 05/06/2010 08:02 PM, oyster wrote:
> I know matplotlib mimics matlab, which offers scientific look.
> but can we use matplotlib to get a skecth(in other words,
> hand-drawing) style for bar/pie/etc in none formalist paper? for
> example, http://teethgrinder.co.uk/open-flash-chart/gallery-bar-7.php
> thanks
With a considerable effort you could use mpl's capabilities to program 
this sort of thing, but it will not be added as an option.
Eric
From: Ryan M. <rm...@gm...> - 2010年05月07日 16:54:03
On Wed, May 5, 2010 at 4:36 PM, Valentino Gonzalez <vgg...@uc...> wrote:
> I am trying to make a scatter plot (it is important that it is a scatter
> plot because I want the markers to be color coded). Each point also has
> errobars associated and since there is no way to plot errorbars on scatter
> plots I am plotting them separately, i.e. plot twice: once with the
> errorbars and no markers and then with only markers as in a scatter plot.
> The problem is that regardless of the order in which I do this, the
> errorbars are alwas on top of the markers of the scatter plot and I would
> like the opposite, markers on top of the errorbars. Can this be done? And
> more generally, how can I choose what goes on top of what?
You should be able to pass zorder=<number> to the plotting functions
to control the order.
Ryan
-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
From: Matt N. <new...@ca...> - 2010年05月07日 16:07:27
Hi Soren,
2010年5月6日 Søren Nielsen <sor...@gm...>:
> Thanks Matt,
>
> The wx.ReleaseMouse() event when called before the wx.MessageBox also works
> great.
>
> I have a similar problem when I want to make a popup menu after the user has
> clicked on a patch (through the pick event) .. it works on Windows but the
> popup menu doesn't show on Linux (or only shows in rare occasions) . A
> wx.ReleaseMouse() doesn't seem to work here.. I've made a sample script that
> shows the problem. It doesn't use the pick event, but the same problem
> applies when using the button_press_event. If I want to go through the pick
> event then of course the button_release_event workaround doesn't work
> either.
>
> Also, clicking the right and left button like crazy to make the popup menu
> show on linux can result in the error:
>
> Traceback (most recent call last):
>  File
> "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_wx.py", line
> 1218, in _onKeyDown
>   FigureCanvasBase.key_press_event(self, key, guiEvent=evt)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py",
> line 1142, in key_press_event
>   event = KeyEvent(s, self, key, self._lastx, self._lasty,
> guiEvent=guiEvent)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py",
> line 970, in __init__
>   LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/backend_bases.py",
> line 813, in __init__
>   axes_list = [a for a in self.canvas.figure.get_axes() if
> a.in_axes(self)]
>  File "/usr/lib64/python2.6/site-packages/matplotlib/axes.py", line 1538,
> in in_axes
>   return self.patch.contains(mouseevent)[0]
>  File "/usr/lib64/python2.6/site-packages/matplotlib/patches.py", line 501,
> in contains
>   x, y = self.get_transform().inverted().transform_point(
>  File "/usr/lib64/python2.6/site-packages/matplotlib/patches.py", line 119,
> in get_transform
>   return self.get_patch_transform() + artist.Artist.get_transform(self)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 1033, in __add__
>   return composite_transform_factory(self, other)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 2004, in composite_transform_factory
>   return CompositeAffine2D(a, b)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 1964, in __init__
>   Affine2DBase.__init__(self)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 1304, in __init__
>   Transform.__init__(self)
>  File "/usr/lib64/python2.6/site-packages/matplotlib/transforms.py", line
> 87, in __init__
>   self._parents = WeakKeyDictionary()
>  File "/usr/lib64/python2.6/weakref.py", line 232, in __init__
>   def remove(k, selfref=ref(self)):
> RuntimeError: maximum recursion depth exceeded while calling a Python object
I don't see that error, but perhaps I didn't emulate "click like
crazy" well enough.
I also see that trying to get a Popup Menu on Linux from events
generated by mpl does not reliably display a menu. In my experience,
a work-around is to replace a direct call to
 wx.Popup(menu)
with
 wx.CallAfter(wx.Popup, menu)
I don't know if this is related to the problem described earlier, in
which the wx object containing the FigureCanvasWxAgg needs to call
ReleaseMouse() on Linux but not Windows. As I said earlier, I have
not investigated very thoroughly so am reluctant to jump to any
conclusions about where the problem really lies and what the best
solution is.
An example with a Popup Menu that displays on right- or left-click of
a FigureCanvasWxAgg is below.
Cheers,
--Matt Newville
#!/usr/bin/python
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
class PlotFrame(wx.Frame):
 def __init__(self, title='Plot Frame', **kwds):
 wx.Frame.__init__(self, None, -1, title=title, **kwds)
 self.panel = wx.Panel(self, -1,size=(600,500))
 self.fig = Figure()
 self.canvas = FigureCanvasWxAgg(self.panel, -1, self.fig)
 self.fig.add_subplot(111)
 self.canvas.mpl_connect('button_press_event',
 self.onMouseButtonClick)
 sizer = wx.BoxSizer(wx.VERTICAL)
 sizer.Add(self.canvas, 1, wx.LEFT |wx.TOP | wx.GROW)
 self.panel.SetSizer(sizer)
 self.SetAutoLayout(True)
 self.Fit()
 def onMouseButtonClick(self, event=None):
 if event is None:
 return
 if event.inaxes:
 menu = wx.Menu()
 if event.button == 1:
 menu.Append(1, 'Left Click: Set as Background file')
 self.Bind(wx.EVT_MENU, self.onSelect1)
 elif event.button == 3:
 menu.Append(1, 'RightClick: Do something else')
 self.Bind(wx.EVT_MENU, self.onSelect2)
 wx.CallAfter(self.PopupMenu, menu)
 def onSelect1(self, event=None):
 print 'select 1'
 def onSelect2(self, event=None):
 print 'select 2'
if __name__ == '__main__':
 app = wx.PySimpleApp()
 frame = PlotFrame(title='Test')
 frame.Show()
 frame.Raise()
 app.MainLoop()
From: Bartosz T. <bar...@gm...> - 2010年05月07日 10:23:40
Dear all,
I am working on figures for my thesis, which consist of several related panels. Each of the panel contains several subplots. In order to arrange the plots I would like to split the figure into two (or more) panels and within each of them create a nested set of subplots. Optimally, the main panels should define their own coordinate systems, such that all of the nested subplot positions are defined within their frame. The syntax could look like that:
panel1 = subplot(1,2,1)
panel2 = subplot(1,2,2)
ax1 = panel1.add_subplot(1,2,1)
ax2 = panel1.add_subplot(1,2,2)
ax3 = panel2.add_subplot(111)
For now it is not possible, because panel1 and panel2 are Axes instances which do not have add_subplot method. The only solution I am aware of is to define all of the subplots by hand using subplot or axes function with positions defined within whole figure coordinate system:
fig = figure()
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,3)
ax3 = fig.add_subplot(1,2,2)
This is of course more difficult, less flexible and requires the user to decide in advance on the layout of the panel. 
Until now I exported each figure to SVG file and arranged them in one file using SVG directives. I also started implementing my own Multipanel class for matplotlib, but it proved out to be not so easy. Therefore I would like to ask if someone has implemented a similar approach or could give me some hints on the implementation.
I will be very grateful for any help.
Cheers,
Bartek
From: oyster <lep...@gm...> - 2010年05月07日 06:02:14
I know matplotlib mimics matlab, which offers scientific look.
but can we use matplotlib to get a skecth(in other words,
hand-drawing) style for bar/pie/etc in none formalist paper? for
example, http://teethgrinder.co.uk/open-flash-chart/gallery-bar-7.php
thanks
From: Michael H. <mh...@ge...> - 2010年05月07日 04:37:36
Hi All,
I am having trouble converting some histogram (hist) code written for an 
earlier version of matplotlib.
It uses the "width" keyword to set up fixed-width bins. However, I can't 
seem to recreate the exact plots, which is what I am trying to do - and 
the new rwidth parameter appears to be of no help, as it only allows me 
to set a scale factor.
Should I be using bins = [...] instead? If yes, has anyway tried 
converting bin widths from pre-rwidth versions of matplotlib before?
Many thanks,
Michael

Showing 9 results of 9

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