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




Showing 17 results of 17

From: John H. <jd...@gm...> - 2009年06月02日 21:44:35
On Tue, Jun 2, 2009 at 4:34 PM, Christopher Barker
<Chr...@no...> wrote:
>> I think the relevant parts are:
>>
>> from matplotlib.figure import Figure
>
>> self.__axl = self.figure.gca()
>
> I don't know what your issue is, but I thin you will be ell served to
> use the OO interface, rather than pylab to write a complex app like this
> -- pylab is designed for simple interactive use and quick scripts. In an
> app, you want full control.
This is the API -- figure is a Figure instance, and gca is a figure
method. pyplot.gca is a wrapper around this method. The Figure
tracks the "current" axes, but the API doesn't really use this method
other than to provide it for pyplot.
But the larger point is still well taken -- you should probably be
using self.figure.add_subplot(111) here rather than gca.
JDH
From: Christopher B. <Chr...@no...> - 2009年06月02日 21:32:35
Tom Vaughan wrote:
>> post some code
>>
> 
> I thought this might be required...
> 
> So the whole thing is excessively complex.
It can be very instructive to write a little app that just tests the 
issue at hand -- it may help you figure out what's wrong, and if not, 
you will have a self-contained sample that you can post here for feedback.
> I think the relevant parts are:
> 
> from matplotlib.figure import Figure
> self.__axl = self.figure.gca()
I don't know what your issue is, but I thin you will be ell served to 
use the OO interface, rather than pylab to write a complex app like this 
-- pylab is designed for simple interactive use and quick scripts. In an 
app, you want full control.
-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: Amit <ror...@gm...> - 2009年06月02日 20:15:39
Hi all,
Has any of you had any luck with creating stacked histograms using 
matplotlib? It seems to work but I have no idea how to label (or add the 
legend) or choose the colors of the stacks. Below is a sample code for 
creating a stacked histogram. Can anyone help please? Unlike the "bar()" 
function, hist() doesn't seem to have the color/colors parameter.
#!/usr/bin/python
import sys
import matplotlib.pyplot as pyplot
import numpy as numpy
page_numbers_one = (100,100,500,600,800)
page_numbers_two = (100,100,500,600,800,100,100,100,100,100)
page_numbers_three = (900,100,500,600,800,500)
pyplot.hist((page_numbers_one,page_numbers_two,page_numbers_three),histtype='barstacked',bins=5)
pyplot.show()
best,
amit shrestha
From: Tom V. <to...@so...> - 2009年06月02日 19:52:00
On Tue, Jun 2, 2009 at 11:59, John Hunter<jd...@gm...> wrote:
> On Tue, Jun 2, 2009 at 1:51 PM, Tom Vaughan <to...@so...> wrote:
>> On Tue, Jun 2, 2009 at 07:33, John Hunter<jd...@gm...> wrote:
>>> On Tue, Jun 2, 2009 at 9:03 AM, Tom Vaughan <to...@so...> wrote:
>>>> Is it possible to add subplots to a figure if I don't know in advance
>>>> how many subplots I need to add?
>>>>
>>>> What I do now is I call add_subplot like add_subplot(i, 1, i) where i
>>>> is 1 initially, and just increases by 1 on each call. This almost
>>>> works. Except the first plot takes up the whole figure, the second
>>>> plot is placed on top of the bottom half of the first plot, etc. Is
>>>> there a way to "resize" the plots when a subplot is added? Or how
>>>> would I "re-plot" the previous subplots?
>>>
>>> See the Axes.change_geometry command
>>>
>>> http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.SubplotBase.change_geometry
>>
>> To follow-up on this a bit, the second, third, etc subplots all seem
>> to get stuck with the first subplot's x-axis. Let's say the first plot
>> is -60 to 60, and the second plot is 2 - 4. The data in the second
>> plot is plotted on the correct scale (2 to 4), but I still see -60 to
>> 60.
>>
>> Actually, this isn't entirely correct. When I add a third subplot, the
>> second subplot becomes correct. So the -60 to 60 only sticks to the
>> most recently added subplot.
>>
>> Any ideas?
>
> post some code
>
I thought this might be required...
We have a variety of telemetry applications that all require some sort
of visual display of data. We've created a widget based upon
matplotlib that can be used stand-alone (reads JSON formatted data
files), or within PyGTK applications and can plot data sets in
"real-time". So the whole thing is excessively complex. I'd be happy
to package up the whole thing if anyone is interested. Currently it
requires the latest Ubuntu release with several additional development
libraries like GLib. What I've posted below is just the abstract plot
widget.
I think the relevant parts are:
 from matplotlib.figure import Figure
 self.figure = Figure()
 self.__subplots = []
 self.subplot_new()
 self.__axl = self.figure.gca()
 self.__axl.yaxis.set_label_position('left')
 self.__axl.yaxis.tick_left()
 self.__axr = self.__axl.twinx()
 self.__axr.yaxis.set_label_position('right')
 self.__axr.yaxis.tick_right()
and then:
 def subplot_new(self):
 nsubplots = len(self.__subplots) + 1
 subplot = self.figure.add_subplot(nsubplots, 1, nsubplots)
 subplot.grid(True)
 self.__subplots.append(subplot)
 self.__subplot = subplot
 for i, subplot in enumerate(self.__subplots):
 subplot.change_geometry(nsubplots, 1, i + 1)
and then:
 def __plot__(self, x, y, style='-', color=0xFF0000,
xlabel=None, ylabel=None):
 IBackend.__plot__(self, x, y, style=style,
color=color, xlabel=xlabel, ylabel=ylabel)
 if xlabel != None:
 self.__subplot.set_xlabel(xlabel)
 if ylabel != None:
 self.__subplot.set_ylabel(ylabel)
 self.__subplot.plot(x, y, style, color='#%06X' % (color))
 self.__subplot.grid(True)
 def plotr(self, *args, **kwargs):
 self.figure.sca(self.__axr)
 if not kwargs.has_key('color'):
 kwargs['color'] = 0x00FF00
 self.__plot__(*args, **kwargs)
 def plotl(self, *args, **kwargs):
 self.figure.sca(self.__axl)
 if not kwargs.has_key('color'):
 kwargs['color'] = 0xFF0000
 self.__plot__(*args, **kwargs)
The whole thing:
from __future__ import with_statement
# standard python libraries
try:
 import json
except:
 import simplejson as json
import re
import os
import time
# matplotlib.sf.net
import matplotlib
import numpy
# www.gtk.org
import gtk
# our own libraries
from elrond.macros import clamp
from elrond.util import Object, Property
def parse(f):
 x = []
 y = []
 fd = open(f, 'r')
 lines = [l.strip() for l in fd.readlines()]
 fd.close()
 for i, line in enumerate(lines):
 data = filter(lambda x: x != '', re.split('[, ]', line.strip()))
 try:
 y.append(float(data[1]))
 x.append(float(data[0]))
 except IndexError:
 y.append(float(data[0]))
 x.append(i)
 return x, y
##
## Backends...
##
class IBackend(Object):
 """The IBackend class is the base implementation for any class
that can produce plots.
 e.g. ASCII art or fancy GUI backends like matplotlib.
 """
 def stripchart(self, filename):
 x_list, y_list = parse(filename)
 self.clear()
 self.props.ymin = 0
 self.props.ymax = 100
 step = 100
 x_first = x_list[0: clamp(step, u=len(x_list))]
 y_first = y_list[0: clamp(step, u=len(y_list))]
 self.props.xmin = 0
 self.props.xmax = len(x_first)
 for i in range(0, len(x_first)):
 self.plotl(x_first[0:i + 1], y_first[0:i + 1])
 self.draw()
 self.plotl(x_list, y_list)
 for i in range(0, len(x_list)):
 self.props.xmin = i + 1
 self.props.xmax = i + 1 + step
 self.draw()
 def open(self, filename):
 self.clear()
 if self.subplotkludge:
 self.subplot_new()
 self.subplotkludge = True
 with open(filename, 'r') as f:
 storage = json.load(f)
 print 'File: %s' % (filename)
 print 'Timestamp: %s' % (storage['timestamp'])
 for data in storage['data']:
 self.plotl(data['x'], data['y'],
xlabel=data['xlabel'], ylabel=data['ylabel'],
 style=data['style'],
color=int(data['color'], 0))
 self.draw()
 if not self.props.overlay:
 self.__storage['data'] = []
 self.__storage['data'].extend(storage['data'])
 def save(self, filename):
 self.__storage['timestamp'] = time.ctime(time.time())
 with open(filename, 'w') as f:
 json.dump(self.__storage, f, indent=8)
 # TODO:
 def stats(self, x, y):
 print ' len =', len(y)
 print ' mean =', numpy.mean(y)
 print ' sum =', sum(y)
 print ' std =', numpy.std(y)
 ymin = numpy.min(y)
 print ' ymin =', ymin
 print ' xmin =', x[y.index(ymin)]
 ymax = numpy.max(y)
 print ' ymax =', ymax
 print ' xmax =', x[y.index(ymax)]
 def __plot__(self, x, y, style=None, color=0xFF0000,
xlabel=None, ylabel=None):
 self.stats(x, y)
 data = {
 'xlabel': xlabel,
 'x': x,
 'ylabel': ylabel,
 'y': y,
 'style': style,
 'color': '0x%06X' % (color)
 }
 if not self.props.overlay:
 self.__storage['data'] = []
 self.__storage['data'].append(data)
 def plotr(self, *args, **kwargs):
 self.__plot__(*args, **kwargs)
 def plotl(self, *args, **kwargs):
 self.__plot__(*args, **kwargs)
 def ploth(self, *args, **kwargs):
 self.__plot__(*args, **kwargs)
 def plotv(self, *args, **kwargs):
 self.__plot__(*args, **kwargs)
 def draw(self, *args, **kwargs):
 pass
 def clear(self, *args, **kwargs):
 pass
 def show(self, *args, **kwargs):
 pass
 def hide(self, *args, **kwargs):
 pass
 def run(self, *args, **kwargs):
 pass
 def __init__(self):
 Object.__init__(self)
 self.__storage = {
 'data': []
 }
class ConsoleBackend(IBackend):
 """This is the simplest of backends. This simply prints to the
console. This backend
 must be used within a ConsoleContainer.
 """
 def __plot__(self, x, y, style=None, color=0xFF0000,
xlabel=None, ylabel=None):
 IBackend.__plot__(self, x, y, style=style,
color=color, xlabel=xlabel, ylabel=ylabel)
 for i in range(0, len(x)):
 print 'x,y[%d] = %.4f, %4f' % (i, x[i], y[i])
class IMatplotlibBackend(IBackend):
 """This backend uses matplotlib to prodce plots. An
ImageContainer or WindowContainer in-turn
 contains this backed to either render the plot to and image or to a GUI.
 """
 def __plot__(self, x, y, style='-', color=0xFF0000,
xlabel=None, ylabel=None):
 IBackend.__plot__(self, x, y, style=style,
color=color, xlabel=xlabel, ylabel=ylabel)
 if xlabel != None:
 self.__subplot.set_xlabel(xlabel)
 if ylabel != None:
 self.__subplot.set_ylabel(ylabel)
 self.__subplot.plot(x, y, style, color='#%06X' % (color))
 self.__subplot.grid(True)
 def plotr(self, *args, **kwargs):
 self.figure.sca(self.__axr)
 if not kwargs.has_key('color'):
 kwargs['color'] = 0x00FF00
 self.__plot__(*args, **kwargs)
 def plotl(self, *args, **kwargs):
 self.figure.sca(self.__axl)
 if not kwargs.has_key('color'):
 kwargs['color'] = 0xFF0000
 self.__plot__(*args, **kwargs)
 def ploth(self, y, style='--', color=0xFF0000):
 self.__subplot.axhline(y, ls=style, color='#%06X' % (color))
 self.__subplot.grid(True)
 def plotv(self, x, style='--', color=0xFF0000):
 self.__subplot.axvline(x, ls=style, color='#%06X' % (color))
 self.__subplot.grid(True)
 def draw(self):
 self.__subplot.axis('auto')
 limits = [self.props.xmin, self.props.xmax,
self.props.ymin, self.props.ymax]
 if filter(lambda x: x != 0, limits):
 self.__subplot.axis(limits)
 self.canvas.draw()
 def clear(self):
 if self.props.overlay:
 return
 self.__subplot.clear()
 self.__subplot.grid(True)
 def subplot_new(self):
 nsubplots = len(self.__subplots) + 1
 subplot = self.figure.add_subplot(nsubplots, 1, nsubplots)
 subplot.grid(True)
 self.__subplots.append(subplot)
 self.__subplot = subplot
 for i, subplot in enumerate(self.__subplots):
 subplot.change_geometry(nsubplots, 1, i + 1)
 def __init__(self):
 IBackend.__init__(self)
 from matplotlib.figure import Figure
 self.figure = Figure()
 self.__subplots = []
 self.subplot_new()
 self.subplotkludge = False
 self.__axl = self.figure.gca()
 self.__axl.yaxis.set_label_position('left')
 self.__axl.yaxis.tick_left()
 self.__axr = self.__axl.twinx()
 self.__axr.yaxis.set_label_position('right')
 self.__axr.yaxis.tick_right()
class MatplotlibImageBackend(IMatplotlibBackend):
 def render(self, filename):
 self.figure.savefig(filename)
 def __init__(self):
 IMatplotlibBackend.__init__(self)
 from matplotlib.backends.backend_cairo \
 import FigureCanvasCairo as FigureCanvas
 self.canvas = FigureCanvas(self.figure)
class MatplotlibWindowBackend(IMatplotlibBackend):
 @Property
 def widget():
 def fget(self):
 self.__widget = gtk.VBox()
 self.__widget.pack_start(self.canvas)
 self.__widget.pack_start(self.toolbar, False, False)
 return self.__widget
 def fset(self, widget):
 self.__widget = widget
 return locals()
 def show(self):
 self.__widget.show()
 self.canvas.show()
 self.toolbar.show()
 def hide(self):
 self.toolbar.hide()
 self.canvas.hide()
 self.__widget.hide()
 def __init__(self):
 IMatplotlibBackend.__init__(self)
 from matplotlib.backends.backend_gtk \
 import FigureCanvasGTK as FigureCanvas
 self.canvas = FigureCanvas(self.figure)
 from matplotlib.backends.backend_gtk \
 import NavigationToolbar2GTK as NavigationToolbar
 self.toolbar = NavigationToolbar(self.canvas, None)
##
## Containers...
##
class IContainer(Object):
 """The IContainer class is the base implementation for any
class that contains IBackends.
 e.g. console wrappers, image only wrappers, or fancy GUI
toolkits like GTK+.
 """
 @Property
 def props():
 def fget(self):
 return self.backend.props
 def fset(self, props):
 self.backend.props = props
 return locals()
 def plotr(self, *args, **kwargs):
 self.backend.plotr(*args, **kwargs)
 def plotl(self, *args, **kwargs):
 self.backend.plotl(*args, **kwargs)
 def ploth(self, *args, **kwargs):
 self.backend.ploth(*args, **kwargs)
 def plotv(self, *args, **kwargs):
 self.backend.plotv(*args, **kwargs)
 def draw(self, *args, **kwargs):
 self.backend.draw(*args, **kwargs)
 def clear(self, *args, **kwargs):
 self.backend.clear(*args, **kwargs)
 def show(self, *args, **kwargs):
 self.backend.show(*args, **kwargs)
 def hide(self, *args, **kwargs):
 self.backend.hide(*args, **kwargs)
 def run(self, *args, **kwargs):
 self.backend.run(*args, **kwargs)
 def stripchart(self, filename):
 self.backend.stripchart(filename)
 def open(self, filename):
 self.backend.open(filename)
 def save(self, filename):
 self.backend.save(filename)
class ConsoleContainer(IContainer):
 def __init__(self):
 IContainer.__init__(self)
 self.backend = ConsoleBackend()
class ImageContainer(IContainer):
 def draw(self, *args, **kwargs):
 IContainer.draw(self, *args, **kwargs)
 self.backend.render('foobar.png')
 def __init__(self):
 IContainer.__init__(self)
 self.backend = MatplotlibImageBackend()
class WindowContainer(IContainer):
 @Property
 def props():
 def fget(self):
 return self.backend.props
 def fset(self, props):
 self.backend.props = props
 widget =
self.__builder.get_object('preferences_xmin_entry')
 widget.set_text(str(self.backend.props.xmin))
 widget =
self.__builder.get_object('preferences_xmax_entry')
 widget.set_text(str(self.backend.props.xmax))
 widget =
self.__builder.get_object('preferences_ymin_entry')
 widget.set_text(str(self.backend.props.ymin))
 widget =
self.__builder.get_object('preferences_ymax_entry')
 widget.set_text(str(self.backend.props.ymax))
 return locals()
 @Property
 def title():
 def fget(self):
 return self.__title
 def fset(self, title):
 self.__title = title
 if not self.__title:
 return
 self.__container.set_title(self.__title)
 return locals()
 def clear(self, *args, **kwargs):
 IContainer.clear(self, *args, **kwargs)
 def show(self, *args, **kwargs):
 IContainer.show(self, *args, **kwargs)
 self.__container.show()
 def hide(self, *args, **kwargs):
 IContainer.hide(self, *args, **kwargs)
 self.__container.hide()
 def run(self):
 gtk.main()
 def on_open_ok_button_clicked(self, widget, data=None):
 self.__open.hide()
 filename = self.__open.get_filename()
 if not filename:
 return
 self.__open.set_filename(filename)
 self.open(filename)
 def on_open_cancel_button_clicked(self, widget, data=None):
 self.__open.hide()
 def on_open_chooser_delete_event(self, widget, data=None):
 self.__open.hide()
 return True
 def on_plot_open_button_clicked(self, widget, data=None):
 self.__open = self.__builder.get_object('open_chooser')
 self.__open.show()
 def on_plot_save_button_clicked(self, widget, data=None):
 if not self.filename:
 self.on_plot_saveas_button_clicked(self, None)
 if self.filename:
 self.save(self.filename)
 def on_saveas_ok_button_clicked(self, widget, data=None):
 self.__saveas.hide()
 filename = self.__saveas.get_filename()
 if not filename:
 return
 self.__saveas.set_filename(filename)
 self.filename = filename
 self.on_plot_save_button_clicked(self, None)
 def on_saveas_cancel_button_clicked(self, widget, data=None):
 self.__saveas.hide()
 def on_saveas_chooser_delete_event(self, widget, data=None):
 self.__saveas.hide()
 return True
 def on_plot_saveas_button_clicked(self, widget, data=None):
 self.__saveas = self.__builder.get_object('saveas_chooser')
 self.__saveas.show()
 def on_preferences_ok_button_clicked(self, widget, data=None):
 self.__preferences.hide()
 widget = self.__builder.get_object('preferences_xmin_entry')
 self.props.xmin = float(widget.get_text())
 widget = self.__builder.get_object('preferences_xmax_entry')
 self.props.xmax = float(widget.get_text())
 widget = self.__builder.get_object('preferences_ymin_entry')
 self.props.ymin = float(widget.get_text())
 widget = self.__builder.get_object('preferences_ymax_entry')
 self.props.ymax = float(widget.get_text())
 self.draw()
 def on_preferences_cancel_button_clicked(self, widget, data=None):
 self.__preferences.hide()
 def on_plot_preferences_button_clicked(self, widget, data=None):
 self.__preferences =
self.__builder.get_object('preferences_dialog')
 self.__preferences.show()
 def on_preferences_dialog_delete_event(self, widget, data=None):
 self.__preferences.hide()
 return True
 def on_plot_overlay_button_toggled(self, widget, data=None):
 self.props.overlay = widget.get_active()
 def on_plot_window_destroy(self, widget, data=None):
 gtk.main_quit()
 def __init__(self, container):
 IContainer.__init__(self)
 self.backend = MatplotlibWindowBackend()
 buildername = os.environ['GRIMA_ETC'] + os.sep + 'grima-plot.ui'
 self.__builder = gtk.Builder()
 self.__builder.add_from_file(buildername)
 self.__builder.connect_signals(self)
 if container:
 self.__container = container
 widget = self.__builder.get_object('plot_embeddable')
 container = self.__builder.get_object('plot_container')
 container.remove(widget)
 self.__container.add(widget)
 else:
 self.__container =
self.__builder.get_object('plot_window')
 # TODO: this should not be needed, but somehow
the widget show'ing order
 # is all screwed up and the window doesn't
display correctly without this
 self.__container.set_default_size(700, 500)
 widget = self.__builder.get_object('plot_backend')
 widget.add(self.backend.widget)
 # TODO:
 self.filename = None
##
## This is the public API...
##
class Plot(Object):
 def __create_display(self):
 if not self.__enabled:
 return
 if self.type == 'console':
 self.__display = ConsoleContainer()
 if self.type == 'image':
 self.__display = ImageContainer()
 if self.type == 'window':
 self.__display = WindowContainer(self.container)
 try:
 self.__display.props = self
 self.__display.title = self.title
 except:
 self.__enabled = False
 @Property
 def enabled():
 def fget(self):
 return self.__enabled
 def fset(self, enabled):
 self.__enabled = enabled
 self.__create_display()
 return locals()
 @Property
 def type():
 def fget(self):
 return self.__type
 def fset(self, type):
 self.__type = type
 self.__create_display()
 return locals()
 @Property
 def title():
 def fget(self):
 return self.__title
 def fset(self, title):
 self.__title = title
 return locals()
 def plotr(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.plotr(*args, **kwargs)
 def plotl(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.plotl(*args, **kwargs)
 def ploth(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.ploth(*args, **kwargs)
 def plotv(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.plotv(*args, **kwargs)
 def draw(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.draw(*args, **kwargs)
 def clear(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.clear(*args, **kwargs)
 def show(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.show(*args, **kwargs)
 def hide(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.hide(*args, **kwargs)
 def run(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.run(*args, **kwargs)
 def stripchart(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.stripchart(*args, **kwargs)
 def open(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.open(*args, **kwargs)
 def save(self, *args, **kwargs):
 if not self.enabled:
 return
 self.__display.save(*args, **kwargs)
 def __init__(self):
 Object.__init__(self)
 self.enabled = False
 self.container = None
 self.type = 'console'
 self.title = None
 # TODO: use preferences
 self.xmin = 0
 self.xmax = 0
 self.ymin = 0
 self.ymax = 0
 self.overlay = False
# Local Variables:
# indent-tabs-mode: nil
# python-continuation-offset: 2
# python-indent: 8
# End:
# vim: ai et si sw=8 ts=8
From: Matthias M. <Mat...@me...> - 2009年06月02日 19:33:23
Dear List, 
boxplots are not plotted correctly in case the 'x' argument has an even
number of elements. So when I do:
import matplotlib.pyplot as plt
import numpy as np
r_odd = np.array([1,2,3,4,5])
plt.boxplot(x=r_odd)
plt.show()
I get the correct boxplot but when I do:
r_even = np.array([1,2,3,4,5,6])
plt.boxplot()
I get a median at 4 which is incorrect. This is also easily compared
with the matlab boxplot function. Do I maybe miss anything here? I use
the most recent svn checkout (v0.98.6svn).
Best
Matthias
From: Sandro T. <mo...@de...> - 2009年06月02日 19:29:01
Better keep the list in the loop ;)
On Tue, Jun 2, 2009 at 21:20, C M <cmp...@gm...> wrote:
> On Tue, Jun 2, 2009 at 1:56 PM, Sandro Tosi <mo...@de...> wrote:
>> - x data values has to be datetime objects (so you have to convert to that)
>> - you have to use plot_data() instead of plot()
>
> OP, note that is a typo for plot_date(), not plot_data().
>
> For converting dates to numbers, also there is in matplotlib.dates
> the date2num function.
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
From: John H. <jd...@gm...> - 2009年06月02日 18:59:01
On Tue, Jun 2, 2009 at 1:51 PM, Tom Vaughan <to...@so...> wrote:
> On Tue, Jun 2, 2009 at 07:33, John Hunter<jd...@gm...> wrote:
>> On Tue, Jun 2, 2009 at 9:03 AM, Tom Vaughan <to...@so...> wrote:
>>> Is it possible to add subplots to a figure if I don't know in advance
>>> how many subplots I need to add?
>>>
>>> What I do now is I call add_subplot like add_subplot(i, 1, i) where i
>>> is 1 initially, and just increases by 1 on each call. This almost
>>> works. Except the first plot takes up the whole figure, the second
>>> plot is placed on top of the bottom half of the first plot, etc. Is
>>> there a way to "resize" the plots when a subplot is added? Or how
>>> would I "re-plot" the previous subplots?
>>
>> See the Axes.change_geometry command
>>
>> http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.SubplotBase.change_geometry
>
> To follow-up on this a bit, the second, third, etc subplots all seem
> to get stuck with the first subplot's x-axis. Let's say the first plot
> is -60 to 60, and the second plot is 2 - 4. The data in the second
> plot is plotted on the correct scale (2 to 4), but I still see -60 to
> 60.
>
> Actually, this isn't entirely correct. When I add a third subplot, the
> second subplot becomes correct. So the -60 to 60 only sticks to the
> most recently added subplot.
>
> Any ideas?
post some code
From: Tom V. <to...@so...> - 2009年06月02日 18:52:00
On Tue, Jun 2, 2009 at 07:33, John Hunter<jd...@gm...> wrote:
> On Tue, Jun 2, 2009 at 9:03 AM, Tom Vaughan <to...@so...> wrote:
>> Is it possible to add subplots to a figure if I don't know in advance
>> how many subplots I need to add?
>>
>> What I do now is I call add_subplot like add_subplot(i, 1, i) where i
>> is 1 initially, and just increases by 1 on each call. This almost
>> works. Except the first plot takes up the whole figure, the second
>> plot is placed on top of the bottom half of the first plot, etc. Is
>> there a way to "resize" the plots when a subplot is added? Or how
>> would I "re-plot" the previous subplots?
>
> See the Axes.change_geometry command
>
> http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.SubplotBase.change_geometry
To follow-up on this a bit, the second, third, etc subplots all seem
to get stuck with the first subplot's x-axis. Let's say the first plot
is -60 to 60, and the second plot is 2 - 4. The data in the second
plot is plotted on the correct scale (2 to 4), but I still see -60 to
60.
Actually, this isn't entirely correct. When I add a third subplot, the
second subplot becomes correct. So the -60 to 60 only sticks to the
most recently added subplot.
Any ideas?
Thanks.
-Tom
From: Sandro T. <mo...@de...> - 2009年06月02日 17:57:25
hi,
On Mon, Jun 1, 2009 at 20:08, pgb205 <pau...@op...> wrote:
>
> et say i have two arrays
> time_array=[00:00:00,00:00:10...17:59:50,18:00:00]
> and
> data_array=[1,12..34,2]
> both of them with the same number of elements.
> I want to graph data_array on y axis vs time_array on x_axis.
> However, I'm unable to do this using matplotlib because it complains
> time_array is not in numeric form.
> I guess I should do plot=(data_array) and somehow mark the x axis with
> time_array data at periodic intervals. Any suggestion on how to mark x-axis
> with times?
Plotting data against time needs this:
- x data values has to be datetime objects (so you have to convert to that)
- you have to use plot_data() instead of plot()
- adjust X axes formatter and locato with date formatter and locator
hope this reference will guide you trhu mpl documentation to have a
working program; in the gallery in the website you can also find an
example for date plotting.
Cheers,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
From: Tom V. <to...@so...> - 2009年06月02日 16:09:25
On Tue, Jun 2, 2009 at 08:40, John Hunter<jd...@gm...> wrote:
> On Tue, Jun 2, 2009 at 10:18 AM, Tom Vaughan <to...@so...> wrote:
>
>> Interestingly, if I were to 'print dir(self.figure.axes[i])' I can see
>> the change_geometry attribute, but when I attempt to call it, I am
>> told "AttributeError: 'AxesSubplot' object has no attribute
>> 'change_geomtry'" This lead me to what I have above.
>>
>
> Check your spelling: 'change_geomtry'
Whoops. Thanks.
-Tom
From: Tom V. <to...@so...> - 2009年06月02日 15:47:21
On Tue, Jun 2, 2009 at 07:33, John Hunter<jd...@gm...> wrote:
> On Tue, Jun 2, 2009 at 9:03 AM, Tom Vaughan <to...@so...> wrote:
>> Is it possible to add subplots to a figure if I don't know in advance
>> how many subplots I need to add?
>>
>> What I do now is I call add_subplot like add_subplot(i, 1, i) where i
>> is 1 initially, and just increases by 1 on each call. This almost
>> works. Except the first plot takes up the whole figure, the second
>> plot is placed on top of the bottom half of the first plot, etc. Is
>> there a way to "resize" the plots when a subplot is added? Or how
>> would I "re-plot" the previous subplots?
>
> See the Axes.change_geometry command
>
> http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.SubplotBase.change_geometry
>
> As in this example::
>
>  import matplotlib.pyplot as plt
>
>  # start with one
>  fig = plt.figure()
>  ax = fig.add_subplot(111)
>  ax.plot([1,2,3])
>
>  # now later you get a new subplot; change the geometry of the existing
>  n = len(fig.axes)
>  for i in range(n):
>    fig.axes[i].change_geometry(n+1, 1, i+1)
Awesome. Thanks.
Strangely this doesn't quite work for me. Luckily I keep a list of my
subplots. So I do:
 def new_subplot(self):
 nsubplots = len(self.__subplots) + 1
 for i, subplot in enumerate(self.__subplots):
 subplot.change_geometry(nsubplots, 1, i + 1)
 subplot = self.figure.add_subplot(nsubplots, 1, nsubplots)
 subplot.grid(True)
 self.__subplots.append(subplot)
 self.__subplot = subplot
Interestingly, if I were to 'print dir(self.figure.axes[i])' I can see
the change_geometry attribute, but when I attempt to call it, I am
told "AttributeError: 'AxesSubplot' object has no attribute
'change_geomtry'" This lead me to what I have above.
Thanks.
-Tom
From: John H. <jd...@gm...> - 2009年06月02日 15:40:37
On Tue, Jun 2, 2009 at 10:18 AM, Tom Vaughan <to...@so...> wrote:
> Interestingly, if I were to 'print dir(self.figure.axes[i])' I can see
> the change_geometry attribute, but when I attempt to call it, I am
> told "AttributeError: 'AxesSubplot' object has no attribute
> 'change_geomtry'" This lead me to what I have above.
>
Check your spelling: 'change_geomtry'
From: Anu P. <apa...@ho...> - 2009年06月02日 15:09:37
Hi,
I was getting segfaults attempting to use matplotlib, and after a few hours of poking, I believe that I have isolated the likely source of the problem. It seems like there is a conflict with player/stage (the robot simulator) in the latest version. Specifically this code works as per the tutorial:
import matplotlib.pyplot
matplotlib.pyplot.plot([1,2,3])
matplotlib.pyplot.ylabel('some numbers')
matplotlib.pyplot.show()
This code, however, does not:
import playerc
import matplotlib.pyplot
matplotlib.pyplot.plot([1,2,3])
matplotlib.pyplot.ylabel('some numbers')
matplotlib.pyplot.show()
This results in a segmentation fault.
Running gdb on this yields the following:
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(no debugging symbols found)
(gdb) set args test.py
(gdb) run
Starting program: /usr/bin/python test.py
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[New Thread 0x7f5495eb06f0 (LWP 25907)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f5495eb06f0 (LWP 25907)]
0x00007f54916b64af in __cxa_allocate_exception () from /usr/lib/libstdc++.so.6
So I am not sure what is going on, my guess is some kind of memory allocation collision? But this diagnosis could be incorrect as I am inexperienced with gdb.
Other related information:
OS: Linux ubuntu 2.6.28-11-generic #42-Ubuntu SMP Fri Apr 17 01:58:03 UTC 2009 x86_64 GNU/Linux 
Matplotlib version: 0.98.6svn (Got the latest SVN checkout after I was having the same issue with the matplotlib installed under Synaptic which is 0.98.5.2)
Numpy: 1.4.0.dev7029 (Again, got latest SVN in a futile attempt to eliminate any possible issues)
Scipy: 0.8.0.dev5795 (same, although I don't think this is even a dependency)
Player: 2.1.2
Stage: 3.0.1
I have not made any changes to the matplotlibrc file, or setup.py, and the verbose-debug option to python yields the following output.
$HOME=/home/anu
CONFIGDIR=/home/anu/.matplotlib
matplotlib data path /usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data
loaded rc file /usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 0.98.6svn
verbose.level debug
interactive is False
units is False
platform is linux2
Lastly, my gcc version is gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) 
I did have matplotlib and player/stage playing nicely in a previous
incarnation, using older versions of both from about 8 months ago. Unfortunately going back is not an option for me, and since this seems like it may be a third party conflict, I may need to refactor my code to avoid loading both in the same script. But any help would be appreciated!
Thanks for your attention!
Anu
_________________________________________________________________
Windows LiveTM: Keep your life in sync. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_BR_life_in_synch_062009 
From: John H. <jd...@gm...> - 2009年06月02日 14:33:45
On Tue, Jun 2, 2009 at 9:03 AM, Tom Vaughan <to...@so...> wrote:
> Is it possible to add subplots to a figure if I don't know in advance
> how many subplots I need to add?
>
> What I do now is I call add_subplot like add_subplot(i, 1, i) where i
> is 1 initially, and just increases by 1 on each call. This almost
> works. Except the first plot takes up the whole figure, the second
> plot is placed on top of the bottom half of the first plot, etc. Is
> there a way to "resize" the plots when a subplot is added? Or how
> would I "re-plot" the previous subplots?
See the Axes.change_geometry command
 http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.SubplotBase.change_geometry
As in this example::
 import matplotlib.pyplot as plt
 # start with one
 fig = plt.figure()
 ax = fig.add_subplot(111)
 ax.plot([1,2,3])
 # now later you get a new subplot; change the geometry of the existing
 n = len(fig.axes)
 for i in range(n):
 fig.axes[i].change_geometry(n+1, 1, i+1)
 # add the new
 ax = fig.add_subplot(n+1, 1, n+1)
 ax.plot([4,5,6])
 plt.show()
JDH
>
> Thanks.
>
> -Tom
>
> ------------------------------------------------------------------------------
> OpenSolaris 2009.06 is a cutting edge operating system for enterprises
> looking to deploy the next generation of Solaris that includes the latest
> innovations from Sun and the OpenSource community. Download a copy and
> enjoy capabilities such as Networking, Storage and Virtualization.
> Go to: http://p.sf.net/sfu/opensolaris-get
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Tom V. <to...@so...> - 2009年06月02日 14:23:57
Is it possible to add subplots to a figure if I don't know in advance
how many subplots I need to add?
What I do now is I call add_subplot like add_subplot(i, 1, i) where i
is 1 initially, and just increases by 1 on each call. This almost
works. Except the first plot takes up the whole figure, the second
plot is placed on top of the bottom half of the first plot, etc. Is
there a way to "resize" the plots when a subplot is added? Or how
would I "re-plot" the previous subplots?
Thanks.
-Tom
From: Norbert N. <Nor...@gm...> - 2009年06月02日 09:08:43
In general, the intent of the Stineman interpolation is not so much to 
follow certain mathematical criteria, but more to provide a "visually 
pleasing" smooth interpolation. In other words: the interpolated curve 
typically is what the human eye would choose as smooth interpolation. It 
gives "good results" for many kinds of "typical" series of data and 
tends to have less overshooting effects than other interpolation 
methods. You will certainly find (or be able to construct) cases where 
this is not the case any more.
If you want a bit more control, you can provide the slopes via the 
optional yp argument. If you want to guarantee a monotonic 
interpolation, you will need to find an alternative algorithm for 
auto-computing the slopes from the points.
If you want to have a look at the original paper, I can send you a scan.
Greetings,
Norbert
Krishna Bhagavatula wrote:
> Hi,
>
> Given that the values of ordinates are changing monotonically, I found 
> that in some cases, stineman interpolation is monotonic even when the 
> slopes are not monotonic. And in other cases, it overshoots. Like in 
> the following one:
>
> x = (0, 10, 70, 100)
> y = (0, 535, 595, 1000)
> xx = arange(0,100,1)
> yy = stineman_interp(xx,x,y,yp=None)
> plot(x,y,'x')
> plot(xx,yy)
>
> Are there some factors that can make the interpolation monotonic, when 
> the slopes are not monotonic? or does it depend on case by case basis?
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT 
> is a gathering of tech-side developers & brand creativity professionals. Meet
> the minds behind Google Creative Lab, Visual Complexity, Processing, & 
> iPhoneDevCamp as they present alongside digital heavyweights like Barbarian 
> Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com 
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
From: Fernando P. <fpe...@gm...> - 2009年06月02日 05:21:48
Hi all,
The time for the Scipy'09 conference is rapidly approaching, and we
would like to both announce the plan for tutorials and solicit
feedback from everyone on topics of interest.
Broadly speaking, the plan is something along the lines of what we
had last year: one continuous 2-day tutorial aimed at introductory
users, starting from the very basics, and in parallel a set of
'advanced' tutorials, consisting of a series of 2-hour sessions on
specific topics.
We will request that the presenters for the advanced tutorials keep
the 'tutorial' word very much in mind, so that the sessions really
contain hands-on learning work and not simply a 2-hour long slide
presentation. We will thus require that all the tutorials will be
based on tools that the attendees can install at least 2 weeks in
advance on all platforms (no "I released it last night" software).
With that in mind, we'd like feedback from all of you on possible
topics for the advanced tutorials. We have space for 8 slots total,
and here are in no particular order some possible topics. At this
point there are no guarantees yet that we can get presentations for
these, but we'd like to establish a first list of preferred topics to
try and secure the presentations as soon as possible.
This is simply a list of candiate topics that various people have
informally suggested so far:
- Mayavi/TVTK
- Advanced topics in matplotlib
- Statistics with Scipy
- The TimeSeries scikit
- Designing scientific interfaces with Traits
- Advanced numpy
- Sparse Linear Algebra with Scipy
- Structured and record arrays in numpy
- Cython
- Sage - general tutorial
- Sage - specific topics, suggestions welcome
- Using GPUs with PyCUDA
- Testing strategies for scientific codes
- Parallel processing and mpi4py
- Graph theory with Networkx
- Design patterns for efficient iterator-based scientific codes.
- Symbolic computing with sympy
We'd like to hear from any ideas on other possible topics of interest,
and we'll then run a doodle poll to gather quantitative feedback with
the final list of candidates.
Many thanks,
f

Showing 17 results of 17

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