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

Showing results of 312

1 2 3 .. 13 > >> (Page 1 of 13)
From: Eric F. <ef...@ha...> - 2011年09月30日 19:22:25
On 09/30/2011 09:12 AM, John Hunter wrote:
> On Thu, Sep 29, 2011 at 11:56 PM, Uri Laserson<las...@mi...> wrote:
>> Hi all,
>> Does anyone have a good solution for taking a line segment and coloring it
>> according to some gradient (where the start and end colors are the only two
>> things specified for the line coloring)?
>
> This example shows how to apply a colormap to a line segment
>
> http://matplotlib.sourceforge.net/examples/pylab_examples/line_collection2.html
>
> JDH
This example might be closer to the request:
http://matplotlib.sourceforge.net/examples/pylab_examples/multicolored_line.html
Eric
From: John H. <jd...@gm...> - 2011年09月30日 19:13:06
On Thu, Sep 29, 2011 at 11:56 PM, Uri Laserson <las...@mi...> wrote:
> Hi all,
> Does anyone have a good solution for taking a line segment and coloring it
> according to some gradient (where the start and end colors are the only two
> things specified for the line coloring)?
This example shows how to apply a colormap to a line segment
http://matplotlib.sourceforge.net/examples/pylab_examples/line_collection2.html
JDH
Hi Jeff,
I computed the convex hull for the points in paths returned by Basemap.drawcountries() and I got the attached map (convex hull algorithm: http://www.scipy.org/Cookbook/Finding_Convex_Hull). You can see the magenta convex hull polygon with U.S. border lines drawn in black as a reference. 
Unfortunately, adding the coastlines to the computation of the convex hull just hungs the program.
I tried running the computation of the convex hull using the polygons retrieved from US Shapefile in http://www.geophysique.be/en/2011/01/27/matplotlib-basemap-tutorial-07-shapefiles-unleached/, but the program hungs due to the huge amount of points too.
I am running out of time to complete this project, so I cannot implement a more efficient version of the convex hull computation to include the coastlines in the process right now. 
QUESTIONS:
- if I plot an open path in the area next to U.S./ Mexico border and I'd like to have the filling of such path to go all the way to the border, I figured I could add extra points to close the path over Mexico in order to fill the area I need. What I do not understand is how can I mask the filled portion over Mexico without masking any portion of the filling over U.S.. i.e. the portion that is outside the polygon shown in the map attached. 
- if I have similar situation in Florida, for which I would like to mask all points that are not over land using is_land() method, how can I do this ?
Thanks
From: jean-michel bain-c. <jea...@gm...> - 2011年09月30日 16:52:39
Hi,
I'd like to show a background image after plotting dates. I use imshow,
which works, but makes the plotted line erased.
If somebody can help, it would be valuable.
thanks in advance
jm
Here is the code. If the line "ax.imshow(img,alpha=0.5)" is commented out,
the graph is correctly displayed.
# -*- coding: utf8 -*-
import datetime, csv
import matplotlib.pyplot as plt
from pylab import figure, show
from matplotlib import image
from matplotlib.dates import MONDAY, SATURDAY
from matplotlib.dates import DayLocator, MonthLocator, WeekdayLocator,
DateFormatter
''' data reading. Here is the data :
Nombre de signalements par jour du 01/08/2011 au 02/10/2011
20110801,8
20111002,10
'''
dates, data = [], []
dataReader = csv.reader(open('data.csv', 'rb'))
for i,row in enumerate(dataReader):
 if i == 0:
 title = row[0]
 else:
 w = row[0]
 w = datetime.date(int(w[0:4]),int(w[4:6]),int(w[6:8])).toordinal()
 dates += [w]
 data += [row[1]]
#
days = DayLocator()
months = MonthLocator()
mondays = WeekdayLocator(MONDAY)
dateFmt = DateFormatter("%d/%m/%Y")
fig = figure()
img = image.imread('carte quartiers Creil.png')
fig.set_facecolor('w')
ax = fig.add_subplot(111)
ax.get_frame().set_alpha(0)
ax.plot_date(dates, data,'-',color='r',alpha=0.75,linewidth=2)
loc = months
if dates[-1] - dates[0] <= 10:
 loc = days
ax.xaxis.set_major_locator(loc)
ax.xaxis.set_major_formatter(dateFmt)
ax.xaxis.set_minor_locator(mondays)
ax.grid(True)
plt.ylabel('nombre de signalements')
plt.title(title)
fig.autofmt_xdate()
ax.imshow(img,alpha=0.5)
show()
From: Holger B. <hol...@sa...> - 2011年09月30日 16:49:14
> That is why you have to work with the 3D objects from
> mpl_toolkits.mplot3d.art3d directly. There isn't a lot of documentation, so
> your best bet is to look at the source code of the module.
Indeed, I was able to extract the necessary pieces from the source
code. In fact I split the function `plot_surface` into two functions
`polyMeshFromMeshGrid` and `plot_surfaceMesh`. The first functions
takes the meshgrid arguments and produces a list of polygons that
should be drawn, the second functions finally displays them (the code
in plot_surface is already structured like this). With this approach I
can plot functions which are made up of several parts which each have
meshgrid structure. Also I can add raw polygons to the mesh.
Maybe this splitting makes sense in the online code as well?
-Holger
def polyMeshFromMeshGrid(self, X, Y, Z, *args, **kwargs):
 rows, cols = Z.shape
 tX, tY, tZ = np.transpose(X), np.transpose(Y), np.transpose(Z)
 rstride = kwargs.pop('rstride', 10)
 cstride = kwargs.pop('cstride', 10)
 if 'facecolors' in kwargs:
 fcolors = kwargs.pop('facecolors')
 else:
 color = np.array(colorConverter.to_rgba(kwargs.pop('color', 'b')))
 fcolors = None
 cmap = kwargs.get('cmap', None)
 norm = kwargs.pop('norm', None)
 vmin = kwargs.pop('vmin', None)
 vmax = kwargs.pop('vmax', None)
 shade = kwargs.pop('shade', cmap is None)
 lightsource = kwargs.pop('lightsource', None)
 # Shade the data
 if shade and cmap is not None and fcolors is not None:
 fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)
 polys = kwargs.pop('polys', [])
 normals = kwargs.pop('normals', [])
 #colset contains the data for coloring: either average z or the facecolor
 colset = kwargs.pop('colset', [])
 for rs in np.arange(0, rows-1, rstride):
 for cs in np.arange(0, cols-1, cstride):
 ps = []
 corners = []
 for a, ta in [(X, tX), (Y, tY), (Z, tZ)]:
 ztop = a[rs][cs:min(cols, cs+cstride+1)]
 zleft = ta[min(cols-1, cs+cstride)][rs:min(rows, rs+rstride+1)]
 zbase = a[min(rows-1, rs+rstride)][cs:min(cols, cs+cstride+1):]
 zbase = zbase[::-1]
 zright = ta[cs][rs:min(rows, rs+rstride+1):]
 zright = zright[::-1]
 corners.append([ztop[0], ztop[-1], zbase[0], zbase[-1]])
 z = np.concatenate((ztop, zleft, zbase, zright))
 ps.append(z)
 # The construction leaves the array with duplicate points, which
 # are removed here.
 ps = zip(*ps)
 lastp = np.array([])
 ps2 = []
 avgzsum = 0.0
 for p in ps:
 if p != lastp:
 ps2.append(p)
 lastp = p
 avgzsum += p[2]
 polys.append(ps2)
 if fcolors is not None:
 colset.append(fcolors[rs][cs])
 else:
 colset.append(avgzsum / len(ps2))
 # Only need vectors to shade if no cmap
 if cmap is None and shade:
 v1 = np.array(ps2[0]) - np.array(ps2[1])
 v2 = np.array(ps2[2]) - np.array(ps2[0])
 normals.append(np.cross(v1, v2))
 return polys, normals, colset
def plot_surfaceMesh(self, polys, normals, colset, *args, **kwargs):
 had_data = self.has_data()
 rows, cols = Z.shape
 rstride = kwargs.pop('rstride', 10)
 cstride = kwargs.pop('cstride', 10)
 if 'facecolors' in kwargs:
 fcolors = kwargs.pop('facecolors')
 else:
 color = np.array(colorConverter.to_rgba(kwargs.pop('color', 'b')))
 fcolors = None
 cmap = kwargs.get('cmap', None)
 norm = kwargs.pop('norm', None)
 vmin = kwargs.pop('vmin', None)
 vmax = kwargs.pop('vmax', None)
 linewidth = kwargs.get('linewidth', None)
 shade = kwargs.pop('shade', cmap is None)
 lightsource = kwargs.pop('lightsource', None)
 polyc = art3d.Poly3DCollection(polys, *args, **kwargs)
 if fcolors is not None:
 if shade:
 colset = self._shade_colors(colset, normals)
 polyc.set_facecolors(colset)
 polyc.set_edgecolors(colset)
 elif cmap:
 colset = np.array(colset)
 polyc.set_array(colset)
 if vmin is not None or vmax is not None:
 polyc.set_clim(vmin, vmax)
 if norm is not None:
 polyc.set_norm(norm)
 else:
 if shade:
 colset = self._shade_colors(color, normals)
 else:
 colset = color
 polyc.set_facecolors(colset)
 self.add_collection(polyc)
 x, y, z = [], [], [];
 for pol in polys:
 for p in pol:
 x.append(p[0])
 y.append(p[1])
 z.append(p[2])
 self.auto_scale_xyz(x, y, z, had_data)
 return polyc
From: Michiel de H. <mjl...@ya...> - 2011年09月30日 15:25:16
Dear all,
I am trying to draw a bar graph in which the bars are filled with a striped pattern rather than a solid color. For example an alternating pattern of red and yellow stripes with an equal width, at a 45 degree angle with respect to the bar. Is there some easy way to do this in matplotlib?
Thank you in advance,
--Michiel.
From: Benjamin R. <ben...@ou...> - 2011年09月30日 15:18:53
On Thu, Sep 29, 2011 at 4:31 PM, Holger Brandsmeier <
hol...@sa...> wrote:
> Hi Ben,
>
> in your example
> > http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html
> the essential line is:
> ax.add_collection3d(poly, zs=zs, zdir='y')
> according to everything I see this can only draw something that is
> made out of several axes parallel parts. I don't think how with such a
> command you could end up with some picture like:
>
> http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/surface3d_demo.hires.png
That is correct. It is only for simple conversions.
>
> What I want to plot should look like that picture (with is part of
> your gallery), just that I don't have a meshgrid data underlying.
>
>
That is why you have to work with the 3D objects from
mpl_toolkits.mplot3d.art3d directly. There isn't a lot of documentation, so
your best bet is to look at the source code of the module.
> Your second example seems to have the same limitation
> http://matplotlib.sourceforge.net/examples/mplot3d/pathpatch3d_demo.html
> just it works with the command
> art3d.pathpatch_2d_to_3d(p, z=0, zdir="x")
>
> The only way that I currently see is that I call
> ax.plot_surface()
> for each quadrilateral of my mesh.
>
>
That would be overkill. However, try checking out the source code for
plot_surface() to see how it creates its Poly3DCollection object.
Ben Root
From: Benjamin R. <ben...@ou...> - 2011年09月30日 15:07:16
On Fri, Sep 30, 2011 at 4:27 AM, Holger Brandsmeier <
hol...@sa...> wrote:
> Dear List,
>
> is it possible to not only assign once color per polygon that is
> plotted, but one color for each vertex, so that the result looks like
> a properly smooth function. Even if I sample the points closely
> enough, in the current approach in almost all of your examples you
> always see the underlying grid (plus it gets very slow in 3D). I don't
> really care much if you interpolate the colors on the 2D projection of
> the polygon or on the real 3D polygon, just any color interpolation is
> better than none.
>
What values for rstride and cstride are you using? By default,
plot_surface() will sample every 10th point of the data array (for
performance reasons). Also, color interpoltion can be turned on by setting
shade to True.
>
> What do you actually understand behind the "antialiasing" parameter of
> 34D plots. It just puzzles me to have such a concept without have a
> concept of pixel shading (and thus an easy way for the above
> interpolation).
>
>
Again, plot_surface() has a shade kwarg. Use it and let me know if it meets
your expectations.
> I noticed that even 2D plots from matplot lib are very pixel dominated:
> http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo.html
>
> But there is the function imshow which doesn't have this artifacts:
> http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo2.html
>
>
for pcolor(), you can set the antialiaseds kwarg to True. The only reason
why imshow looks good in the second example is because the interpolation was
set to bilinear, and I think that automatically sets antialiasing to True.
> So is it possible to do something like imshow for 3D as well?
>
>
imshow() in 2d was not designed in such a way to yet be used in 3d, but I
think there is already a feature request filed for that.
Try shade=True for plot_surface() and see how that looks for you.
Cheers!
Ben Root
From: Neal B. <ndb...@gm...> - 2011年09月30日 14:55:14
David Hoese wrote:
> Neal,
> 
> I do something similar to this where data that I'm plotting in a 2D line
> plot comes from a UDP socket and some memory mapped files. To
> accomplish the live updating I have a mix of your #2 and #3. I have a
> main GUI thread that displays the plots, then I have a second thread
> that gets data from a python generator and signals the GUI thread when
> that new data has arrived. Inside the generator is where I have socket
> communications and select calls. Hope this helps.
> 
Haven't tried it, but I did notice QSocketNotifier, which sounds like it may be 
what I need if I want to hook into qt event loop to implement as single-thread, 
single-process.
> -Dave
> 
> On 9/30/11 9:10 AM,
> mat...@li...
> wrote:
>> Message: 4
>> Date: 2011年9月30日 07:37:49 -0400
>> From: Neal Becker<ndb...@gm...>
>> Subject: [Matplotlib-users] how would you do this (animated bargraph)
>> To:mat...@li...
>> Message-ID:<j649me$ug41ドル...@do...>
>> Content-Type: text/plain; charset="ISO-8859-1"
>>
>> I just put together an animated bargraph to show results from a realtime
>> process.
>>
>> I used this as an example:
>> http://matplotlib.sourceforge.net/examples/animation/animation_blit_qt4.html
>>
>> The tricky part for me was that in the original design, there was a realtime
>> process running. I have to write some information to my hardware (at a rate
>> of
>> about 1/360ms). To do this, I have a kernel driver that uses 'read' to tell
>> the user space when an interrupt has occurred, which is when the user space
>> should write new information to the hardware.
>>
>> So I don't know how or if this could be hooked into qt event processing. 
>> Just for a quick-and-dirty demo, I just removed the realtime processing from
>> the user-space and put it in the kernel driver, so now my bargraph display
>> can simply update on a periodic timer, and the userspace code has no realtime
>> requirement. But this is just a kludge.
>>
>> So I wonder how other's would solve this? I'm thinking it would be either:
>>
>> 1) multi-process
>> 2) multi-thread
>> 3) 1 process, but somehow hook my realtime events into qt's event loop.
>>
>> For #3, my device driver has a filedescriptor, that could use select to
>> detect the interrupt (rather than blocking read call).
>>
>> #1 and #2 seem complicated.
> 
From: Benjamin R. <ben...@ou...> - 2011年09月30日 14:36:26
2011年9月30日 Александров Петр <pet...@ma...>
> How to make a plot of a discontinuous 1d function without line at a
> function jump. An example is shown on a picture. This was plotted by:
> import numpy
> from matplotlib import pyplot
> x = numpy.linspace(-1.0, 1.0, 100)
> y = numpy.sign(x) * numpy.cos(x)
> axes = pyplot.gca()
> axes.set_ylim(-1.1, 1.1)
> pyplot.plot(x, y)
>
>
If you happen to know where the discontinuity is, then you could do two
separate plot commands. Automatically, it is harder. Maybe something like
this would help:
threshold = 1000.0
# Use gradient instead of diff because it returns an array of the same shape
dydx = numpy.gradient(y) / numpy.gradient(x)
idx = (numpy.abs(dydx) < threshold)
axes.plot(x[idx], y[idx])
Although, that gets rid of valid data points. Another trick would be to
rebuild the x and y arrays, but with NaNs placed between datapoints that
would form the discontinuity. matplotlib automatically treats NaNs as a
indicator to break a line.
Ben Root
From: Sebastian B. <seb...@si...> - 2011年09月30日 14:31:38
Hey,
On Fri, 2011年09月30日 at 17:31 +0400, Александров Петр wrote:
> How to make a plot of a discontinuous 1d function without line at a
> function jump. An example is shown on a picture. This was plotted by:
> import numpy
> from matplotlib import pyplot
> x = numpy.linspace(-1.0, 1.0, 100)
> y = numpy.sign(x) * numpy.cos(x)
> axes = pyplot.gca()
> axes.set_ylim(-1.1, 1.1)
> pyplot.plot(x, y)
> 
You can plot two lines, or use nan (or masked arrays I guess) to break
the line. in this case, this would be something like:
x = np.linspace(-1.0, 1.0, 101) # 101 as then 0 is included
s = np.sign(x)
s[s==0] = np.nan
y = s * np.cos(x)
plt.plot(x, y)
Regards,
Sebastian
> 
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously valuable.
> Why? It contains a definitive record of application performance, security
> threats, fraudulent activity, and more. Splunk takes this data and makes
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2dcopy2
> _______________________________________________ Matplotlib-users mailing list Mat...@li... https://lists.sourceforge.net/lists/listinfo/matplotlib-users
From: Fabrice S. <si...@lm...> - 2011年09月30日 14:22:08
Le vendredi 30 septembre 2011 à 17:31 +0400, Александров Петр a écrit :
> How to make a plot of a discontinuous 1d function without line at a
> function jump. An example is shown on a picture. This was plotted by:
> import numpy
> from matplotlib import pyplot
> x = numpy.linspace(-1.0, 1.0, 100)
> y = numpy.sign(x) * numpy.cos(x)
> axes = pyplot.gca()
> axes.set_ylim(-1.1, 1.1)
> pyplot.plot(x, y)
idx = (x>0)
pyplot(x[idx],y[idx])
idx = numpy.logical_not(idx)
pyplot(x[idx],y[idx])
-- 
Fabrice Silva
From: David H. <dh...@gm...> - 2011年09月30日 14:21:45
Neal,
I do something similar to this where data that I'm plotting in a 2D line 
plot comes from a UDP socket and some memory mapped files. To 
accomplish the live updating I have a mix of your #2 and #3. I have a 
main GUI thread that displays the plots, then I have a second thread 
that gets data from a python generator and signals the GUI thread when 
that new data has arrived. Inside the generator is where I have socket 
communications and select calls. Hope this helps.
-Dave
On 9/30/11 9:10 AM, mat...@li... wrote:
> Message: 4
> Date: 2011年9月30日 07:37:49 -0400
> From: Neal Becker<ndb...@gm...>
> Subject: [Matplotlib-users] how would you do this (animated bargraph)
> To:mat...@li...
> Message-ID:<j649me$ug41ドル...@do...>
> Content-Type: text/plain; charset="ISO-8859-1"
>
> I just put together an animated bargraph to show results from a realtime
> process.
>
> I used this as an example:
> http://matplotlib.sourceforge.net/examples/animation/animation_blit_qt4.html
>
> The tricky part for me was that in the original design, there was a realtime
> process running. I have to write some information to my hardware (at a rate of
> about 1/360ms). To do this, I have a kernel driver that uses 'read' to tell the
> user space when an interrupt has occurred, which is when the user space should
> write new information to the hardware.
>
> So I don't know how or if this could be hooked into qt event processing. Just
> for a quick-and-dirty demo, I just removed the realtime processing from the
> user-space and put it in the kernel driver, so now my bargraph display can
> simply update on a periodic timer, and the userspace code has no realtime
> requirement. But this is just a kludge.
>
> So I wonder how other's would solve this? I'm thinking it would be either:
>
> 1) multi-process
> 2) multi-thread
> 3) 1 process, but somehow hook my realtime events into qt's event loop.
>
> For #3, my device driver has a filedescriptor, that could use select to detect
> the interrupt (rather than blocking read call).
>
> #1 and #2 seem complicated.
From: Neal B. <ndb...@gm...> - 2011年09月30日 11:38:24
I just put together an animated bargraph to show results from a realtime 
process.
I used this as an example:
http://matplotlib.sourceforge.net/examples/animation/animation_blit_qt4.html
The tricky part for me was that in the original design, there was a realtime 
process running. I have to write some information to my hardware (at a rate of 
about 1/360ms). To do this, I have a kernel driver that uses 'read' to tell the 
user space when an interrupt has occurred, which is when the user space should 
write new information to the hardware.
So I don't know how or if this could be hooked into qt event processing. Just 
for a quick-and-dirty demo, I just removed the realtime processing from the 
user-space and put it in the kernel driver, so now my bargraph display can 
simply update on a periodic timer, and the userspace code has no realtime 
requirement. But this is just a kludge.
So I wonder how other's would solve this? I'm thinking it would be either:
1) multi-process
2) multi-thread
3) 1 process, but somehow hook my realtime events into qt's event loop.
For #3, my device driver has a filedescriptor, that could use select to detect 
the interrupt (rather than blocking read call).
#1 and #2 seem complicated.
From: Holger B. <hol...@sa...> - 2011年09月30日 09:28:03
Dear List,
is it possible to not only assign once color per polygon that is
plotted, but one color for each vertex, so that the result looks like
a properly smooth function. Even if I sample the points closely
enough, in the current approach in almost all of your examples you
always see the underlying grid (plus it gets very slow in 3D). I don't
really care much if you interpolate the colors on the 2D projection of
the polygon or on the real 3D polygon, just any color interpolation is
better than none.
What do you actually understand behind the "antialiasing" parameter of
34D plots. It just puzzles me to have such a concept without have a
concept of pixel shading (and thus an easy way for the above
interpolation).
I noticed that even 2D plots from matplot lib are very pixel dominated:
http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo.html
But there is the function imshow which doesn't have this artifacts:
http://matplotlib.sourceforge.net/examples/pylab_examples/pcolor_demo2.html
So is it possible to do something like imshow for 3D as well?
-Holger
From: Nils W. <nw...@ia...> - 2011年09月30日 07:33:35
On 2011年9月29日 14:56:21 +0200
 "Nils Wagner" <nw...@ia...> wrote:
> Hi all,
> 
> How can I add a printer button to the Navigation toolbar 
> http://matplotlib.sourceforge.net/users/navigation_toolbar.html 
> ?
> 
> A small example for QT would be awesome.
> 
> Thanks in advance.
> 
> Nils
> 
How can I adapt the example
http://matplotlib.sourceforge.net/examples/user_interfaces/printing_in_wx.html
for QT ?
Nils
From: Uri L. <las...@mi...> - 2011年09月30日 04:57:06
Hi all,
Does anyone have a good solution for taking a line segment and coloring it
according to some gradient (where the start and end colors are the only two
things specified for the line coloring)?
Thanks!
Uri
...................................................................................
Uri Laserson
Graduate Student, Biomedical Engineering
Harvard-MIT Division of Health Sciences and Technology
M +1 917 742 8019
las...@mi...
From: Holger B. <hol...@sa...> - 2011年09月29日 21:44:52
Hi Ben,
in your example
> http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html
the essential line is:
 ax.add_collection3d(poly, zs=zs, zdir='y')
according to everything I see this can only draw something that is
made out of several axes parallel parts. I don't think how with such a
command you could end up with some picture like:
 http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/surface3d_demo.hires.png
What I want to plot should look like that picture (with is part of
your gallery), just that I don't have a meshgrid data underlying.
Your second example seems to have the same limitation
 http://matplotlib.sourceforge.net/examples/mplot3d/pathpatch3d_demo.html
just it works with the command
 art3d.pathpatch_2d_to_3d(p, z=0, zdir="x")
The only way that I currently see is that I call
 ax.plot_surface()
for each quadrilateral of my mesh.
I'm actually only looking for a function which can shade a set of
polygons that make up a picture like
 http://matplotlib.sourceforge.net/plot_directive/mpl_examples/mplot3d/surface3d_demo.hires.png
I might be able to limit the polygons to be quadrilaterals only. The
mesh will be nice in the sense that polygons do not intersect.
Otherwise the list of polygons should be arbitrary.
-Holger
On Thu, Sep 29, 2011 at 17:33, Benjamin Root <ben...@ou...> wrote:
> On Thu, Sep 29, 2011 at 4:09 AM, Holger Brandsmeier
> <hol...@sa...> wrote:
>>
>> Dear list,
>>
>> is there an equivalent function to matlabs patch() function in matplotlib?
>> http://dali.feld.cvut.cz/ucebna/matlab/techdoc/ref/patch.html
>> That means a function which does not require its X,Y,Z arguments to
>> come from a prior call to meshgrid? That is at least what I believe to
>> be the requirement for Axes3DSubplot.plot_surface.
>>
>> In matlab you can pass n x k matrices as X,Y,Z argument, which then
>> means that there are n Polygons (each with k vertices) and they each
>> get shaded. The problem with the meshgrid structure is, that an
>> unstructured mesh does not have this tensor structure, so if I have
>> 1000 quadrilaterals, then I would have to call
>> `Axes3DSubplot.plot_surface` for each of them separately. At least
>> with `gtkagg` this even seems to fail with z-buffer problem. Btw.
>> which backend to you recommend for 3D plots?
>>
>> -Holger
>
> There are some ways to do what you want. For some simple examples:
>
> http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html
> http://matplotlib.sourceforge.net/examples/mplot3d/pathpatch3d_demo.html
>
> These examples show how you can take a normal 2D matplotlib patch and
> convert it into a 3D object.
>
> Unfortunately, I do not have any example on hand on how to work with the 3D
> versions of the objects directly, but that is possible. You can find the
> classes in the 'mpl_toolkits.mplot3d.art3d' module. Do keep in mind that
> mplot3d is currently only meant for simple 3D plots, as it can not properly
> lay out a 3D environment (intersecting polygons, for example will look
> Escher-like). As for backends, the only thing that mplot3d requires is that
> it uses an Agg-based backend so that it can perform arbitrary rotation of
> text elements (for axes labels).
>
> I hope this helps a bit.
> Ben Root
>
>
-- 
Holger Brandsmeier, SAM, ETH Zürich
http://www.sam.math.ethz.ch/people/bholger
From: Filipe P. A. F. <oc...@gm...> - 2011年09月29日 15:45:11
Hi I noticed that Basemap 1.0.2 will replace the old pyshapelib with
the pure python shapelib.py. However, that did break some of my
scripts when I use custom shapefiles.
Here is a picture from Basemap 1.0.1,
http://imageshack.us/photo/my-images/69/basemap101.png/
and here the same script under Basemap 1.0.2,
http://imageshack.us/photo/my-images/854/basemap102.png/
and here is the script:
http://pastebin.com/WfePCFJi
It probably has something to do with the way shapelib.py handle the
lines, As soon as I have some time I'll take a better look into that,
but I would like to ask if anyone has seen this before and/or if you
have a suggestion/solution for it.
Thanks, Filipe
From: Benjamin R. <ben...@ou...> - 2011年09月29日 15:33:59
On Thu, Sep 29, 2011 at 4:09 AM, Holger Brandsmeier <
hol...@sa...> wrote:
> Dear list,
>
> is there an equivalent function to matlabs patch() function in matplotlib?
> http://dali.feld.cvut.cz/ucebna/matlab/techdoc/ref/patch.html
> That means a function which does not require its X,Y,Z arguments to
> come from a prior call to meshgrid? That is at least what I believe to
> be the requirement for Axes3DSubplot.plot_surface.
>
> In matlab you can pass n x k matrices as X,Y,Z argument, which then
> means that there are n Polygons (each with k vertices) and they each
> get shaded. The problem with the meshgrid structure is, that an
> unstructured mesh does not have this tensor structure, so if I have
> 1000 quadrilaterals, then I would have to call
> `Axes3DSubplot.plot_surface` for each of them separately. At least
> with `gtkagg` this even seems to fail with z-buffer problem. Btw.
> which backend to you recommend for 3D plots?
>
> -Holger
There are some ways to do what you want. For some simple examples:
http://matplotlib.sourceforge.net/examples/mplot3d/polys3d_demo.html
http://matplotlib.sourceforge.net/examples/mplot3d/pathpatch3d_demo.html
These examples show how you can take a normal 2D matplotlib patch and
convert it into a 3D object.
Unfortunately, I do not have any example on hand on how to work with the 3D
versions of the objects directly, but that is possible. You can find the
classes in the 'mpl_toolkits.mplot3d.art3d' module. Do keep in mind that
mplot3d is currently only meant for simple 3D plots, as it can not properly
lay out a 3D environment (intersecting polygons, for example will look
Escher-like). As for backends, the only thing that mplot3d requires is that
it uses an Agg-based backend so that it can perform arbitrary rotation of
text elements (for axes labels).
I hope this helps a bit.
Ben Root
From: Filipe P. A. F. <oc...@gm...> - 2011年09月29日 13:17:28
On Wed, Sep 28, 2011 at 16:39, Jeff Whitaker <js...@fa...> wrote:
> On 9/28/11 2:19 PM, Isidora wrote:
>> Hi Filipe,
>>
>> I have just seen your answers. I am trying to plot on a background GIF map, lines like the ones you can see in http://www.spc.noaa.gov/products/outlook/day1probotlk_2000_wind.gif. I can plot the lines as you see them in this link without a problem. However, because those lines are not closed polygons, the filling extends only to a straight line between first and last point of the curve.
>> I want the filling to extend all the way to the border of United States.
>>
>> Since drawcountries() return a Collection of paths without any metadata identifying the country/countries been separated by it, I cannot use it to mask the area outside ofthe borders out.
>>
>> I'd appreciate any link/documentation I could read to help me resolve this issue.
>>
>> Thank you
> Isidora
>
> Nobody has tried to do this (that I know of), so I can't point you to
> anything specific. Did you see my message about creating a gridded
> field (say 1's for points inside and 0's for points outside the region),
> the calling contour to draw the line? You can use the is_land method to
> determine if a point is over land or not, but there is not way to
> determine whether a given point is inside a country. As you found out,
> there is no metadata associated with the coastlines or political
> boundary lines.
>
> The fillcontinents method returns a list matplotlib polygon instances
> that represent the land areas. One of them is North America, and could
> be used to clip your line segments - but there is no easy way to
> determine which one it is.
>
> If you can find a shapefile that just contains a CONUS polygon, you
> could use that I suppose.
I guess that Jeff suggestion of manipulation a shapefile might be the
easiest way to do this, here is an example that might help you.
http://www.geophysique.be/en/2011/01/27/matplotlib-basemap-tutorial-07-shapefiles-unleached/
-Filipe
> -Jeff
>
> --
> Jeffrey S. Whitaker     Phone : (303)497-6313
> Meteorologist        FAX  : (303)497-6449
> NOAA/OAR/PSD R/PSD1    Email : Jef...@no...
> 325 Broadway        Office : Skaggs Research Cntr 1D-113
> Boulder, CO, USA 80303-3328 Web  : http://tinyurl.com/5telg
>
>
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
From: Nils W. <nw...@ia...> - 2011年09月29日 12:59:41
Hi all,
How can I add a printer button to the Navigation toolbar 
http://matplotlib.sourceforge.net/users/navigation_toolbar.html 
?
A small example for QT would be awesome.
Thanks in advance.
 Nils
From: <fdu...@gm...> - 2011年09月29日 11:49:52
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 26 20:42:25 2011
http://stackoverflow.com/questions/5089030/how-do-i-create-a-radial-cluster-like-the-following-code-example-in-python
colorbar:
 http://matplotlib.sourceforge.net/api/colorbar_api.html
 http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.colorbar
 http://matplotlib.sourceforge.net/examples/api/colorbar_only.html
@author: Xiao Jianfeng
"""
import scipy
import pylab
import scipy.cluster.hierarchy as sch
import scipy.spatial.distance as dist
from matplotlib import mpl
#def heatmap(x, colside_colors=None, rowside_colors=None):
def heatmap():
 """
 x is a m by n ndarray, m observations, n genes
 """
 x = scipy.rand(20, 30)
 #x = scipy.loadtxt("f:/learn/heatmap/tst.data")
 x = x*10
 cmap=pylab.cm.YlGnBu
 norm = mpl.colors.Normalize(vmin=x.min(), vmax=x.max())
 fig = pylab.figure(figsize=(8,8))
 ## calculate positions for all elements
 # ax1, dendrogram 1, on the left of the heatmap
 [ax1_x, ax1_y, ax1_w, ax1_h] = [0.05,0.1,0.2,0.6]
 width_between_ax1_axr = 0.01
 height_between_ax1_axc = 0.01
 # axr, row side colorbar 
 [axr_x, axr_y, axr_w, axr_h] = [0.31,0.1,0.02,0.6]
 axr_x = ax1_x + ax1_w + width_between_ax1_axr
 axr_y = ax1_y; axr_h = ax1_h
 width_between_axr_axm = 0.01
 # axc, column side colorbar
 [axc_x, axc_y, axc_w, axc_h] = [0.4,0.63,0.5,0.02]
 axc_x = axr_x + axr_w + width_between_axr_axm
 axc_y = ax1_y + ax1_h + height_between_ax1_axc
 height_between_axc_ax2 = 0.01
 # axm, heatmap for the data matrix
 [axm_x, axm_y, axm_w, axm_h] = [0.4,0.1,0.5,0.5]
 axm_x = axr_x + axr_w + width_between_axr_axm
 axm_y = ax1_y; axm_h = ax1_h
 axm_w = axc_w
 # ax2, dendrogram 2, on the top of the heatmap
 [ax2_x, ax2_y, ax2_w, ax2_h] = [0.3,0.72,0.6,0.2]
 ax2_x = axr_x + axr_w + width_between_axr_axm
 ax2_y = ax1_y + ax1_h + height_between_ax1_axc + axc_h + height_between_axc_ax2
 ax2_w = axc_w
 # axcb
 [axcb_x, axcb_y, axcb_w, axcb_h] = [0.10,0.75,0.15,0.1]
 # Compute and plot left dendrogram.
 d1 = dist.pdist(x)
 D1 = dist.squareform(d1) # full matrix
 # postion = [left(x), bottom(y), width, height]
 ax1 = fig.add_axes([ax1_x, ax1_y, ax1_w, ax1_h], frame_on=True) # frame_on may be False
 Y1 = sch.linkage(D1, method='single')
 #Y = sch.linkage(D1, method='centroid')
 Z1 = sch.dendrogram(Y1, orientation='right')
 #ax1.set_xticks([])
 #ax1.set_yticks([])
 # Plot rowside colors
 # axr --> axes for row side colorbar
 axr = fig.add_axes([axr_x, axr_y, axr_w, axr_h]) # axes for column side colorbar
 dr = scipy.random.randint(low=0, high=5, size=(x.shape[0], 1))
 # there are two methods to generate discrete colormap:
 # matplotlib.cm.get_cmap() and mpl.colros.ListedColormap()
 #cmap_r = mpl.cm.get_cmap('hot', lut=5)
 cmap_r = mpl.colors.ListedColormap(['r', 'g', 'b', 'y', 'w'])
 im_c = axr.pcolor(dr, cmap=cmap_r)
 axr.set_xticks([])
 axr.set_yticks([])
 # Compute and plot top dendrogram.
 d2 = dist.pdist(x.T)
 D2 = dist.squareform(d2)
 ax2 = fig.add_axes([ax2_x, ax2_y, ax2_w, ax2_h], frame_on=True)
 Y2 = sch.linkage(D2, method='single')
 Z2 = sch.dendrogram(Y2)
 #ax2.set_xticks([])
 #ax2.set_yticks([])
 # Plot distance matrix.
 axm = fig.add_axes([axm_x, axm_y, axm_w, axm_h]) # axes for the data matrix
 idx1 = Z1['leaves']
 idx2 = Z2['leaves']
 xt = x[idx1,:] # xt is transformed x
 xt = xt[:,idx2]
 im = axm.pcolor(xt, cmap=cmap)
 axm.set_xticks([])
 #fix_verts(ax1,1)
 #fix_verts(ax2,0)
 # Add text
 texts_row = [("%s_" % i)*4 for i in range(x.shape[0])]
 texts_col = [("%s_" % i)*4 for i in range(x.shape[1])]
 for i in range(x.shape[0]):
 axm.text(x.shape[1]+0.5, i, texts_row[idx1[i]])
 for i in range(x.shape[1]):
 axm.text(i, -0.5, texts_col[idx2[i]], rotation=270, verticalalignment="top") # rotation could also be degrees
 # Plot colside colors
 # axc --> axes for column side colorbar
 axc = fig.add_axes([axc_x, axc_y, axc_w, axc_h]) # axes for column side colorbar
 dc = scipy.random.randint(low=0, high=5, size=(1, x.shape[1]))
 # there are two methods to generate discrete colormap:
 # matplotlib.cm.get_cmap() and mpl.colros.ListedColormap()
 #cmap_c = mpl.cm.get_cmap('hot', lut=5)
 cmap_c = mpl.colors.ListedColormap(['r', 'g', 'b', 'y', 'w'])
 im_c = axc.pcolor(dc, cmap=cmap_c)
 axc.set_yticks([])
 # Plot colorbar
 axcb = fig.add_axes([axcb_x, axcb_y, axcb_w, axcb_h], frame_on=False) # axes for colorbar
 cb = mpl.colorbar.ColorbarBase(axcb, cmap=cmap, norm=norm, orientation='horizontal')
 axcb.set_title("colorkey")
 cb.set_label("add label here")
 #axcb.set_xticks([])
 #axcb.set_yticks([])
 pylab.show()
#-----------------------------------------
if __name__ == '__main__':
 heatmap()
From: Holger B. <hol...@sa...> - 2011年09月29日 09:22:05
Dear list,
is there an equivalent function to matlabs patch() function in matplotlib?
 http://dali.feld.cvut.cz/ucebna/matlab/techdoc/ref/patch.html
That means a function which does not require its X,Y,Z arguments to
come from a prior call to meshgrid? That is at least what I believe to
be the requirement for Axes3DSubplot.plot_surface.
In matlab you can pass n x k matrices as X,Y,Z argument, which then
means that there are n Polygons (each with k vertices) and they each
get shaded. The problem with the meshgrid structure is, that an
unstructured mesh does not have this tensor structure, so if I have
1000 quadrilaterals, then I would have to call
`Axes3DSubplot.plot_surface` for each of them separately. At least
with `gtkagg` this even seems to fail with z-buffer problem. Btw.
which backend to you recommend for 3D plots?
-Holger
-- 
Holger Brandsmeier, SAM, ETH Zürich
http://www.sam.math.ethz.ch/people/bholger
From: rajtendulkar <pra...@gm...> - 2011年09月29日 07:21:38
Dear Ben,
Thank you very much your reply.
I understood that there is problem the way plot_wireframe() function
requires the data.
However, I am trying to understand how exactly it needs the data.
For example to understand I took this random input data and did the plot - 
(I took random points because in some cases it was giving me straight line)
X = np.array([[1,2,3], [4, 5, 6]])
Y = np.array([[37,85,19], [120,191,612]])
Z = np.array([[103,140,415], [16,217,718]])
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
And it gave me a wireframe 3D graph.
However, I have questions regarding this plot - 
1. How exactly the function plot_wireframe() interprets and plots the data?
How are the co-ordinates determined?
I tried to locate the points for example (1,37,103) (2,85,140) and so on...
but I don't think it is like that.
2. why does it require multiple dimension
If my input data is -
X = np.array([1,2,3])
Y = np.array([37,85,19])
Z = np.array([103,140,415])
It gives an error ValueError: need more than 1 value to unpack
Can you please tell me about these? :)
Thank you very much for your reply.
Regards,
Raj
Benjamin Root-2 wrote:
> 
> On Tue, Sep 27, 2011 at 11:55 AM, rajtendulkar
> <pra...@gm...>wrote:
> 
>> Dear Forum, I am a completely new user to matplotlib. I want to plot a 3D
>> wireframe / surface plot with matplotlib. I am trying to understand how
>> to
>> arrange the data so that I will get the correct plot. After trying a lot
>> and
>> taking reference from different examples, I wrote a code given in the
>> file
>> temp.py <http://old.nabble.com/file/p32534574/temp.py>. Can anyone please
>> tell me, how can I fix it to get a correct wireframe or surface plot? I
>> don't understand the array Z how it should look like. Thank You, Raj
>> temp.py <http://old.nabble.com/file/p32534574/temp.py>
>>
> 
> 
> I don't think your data is well-formed. The input X, Y, and Z needs to be
> 2D with the same shape. I am confused by your x and y data, which you
> then
> pass into meshgrid. To illustrate, meshgrid does this:
> 
> for:
> x = [1, 2, 3, 4, 5]
> y = [1, 2, 3]
> 
> then the command:
> X, Y = numpy.meshgrid(x, y)
> 
> produces (for X):
> array([[1, 2, 3, 4, 5],
> [1, 2, 3, 4, 5],
> [1, 2, 3, 4, 5]])
> 
> and (for Y):
> array([[1, 1, 1, 1, 1],
> [2, 2, 2, 2, 2],
> [3, 3, 3, 3, 3]])
> 
> Your x and y look like they are flattened versions of these. In addition,
> your z doesn't seem to have enough values to fit the domain.
> 
> Ben Root
> 
> ------------------------------------------------------------------------------
> All the data continuously generated in your IT infrastructure contains a
> definitive record of customers, application performance, security
> threats, fraudulent activity and more. Splunk takes this data and makes
> sense of it. Business sense. IT sense. Common sense.
> http://p.sf.net/sfu/splunk-d2dcopy1
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
> 
> 
-- 
View this message in context: http://old.nabble.com/Plotting-in-3D.-how-to-specify-the-data--tp32534574p32551053.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
9 messages has been excluded from this view by a project administrator.

Showing results of 312

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