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






Showing 21 results of 21

From: Ondrej C. <on...@ce...> - 2009年05月22日 23:23:01
Attachments: t.py
> Ok, I made a progress, it seems it's working. Script and picture
Forgot to attach the script.
Ondrej
From: Ondrej C. <on...@ce...> - 2009年05月22日 23:22:25
Attachments: mpl2.png
On Fri, May 22, 2009 at 3:37 PM, Ondrej Certik <on...@ce...> wrote:
> Thanks a lot John. I tried that and it does what I want. I just need
> to convert and probably average my 3 different values at the 3
> vertices of the triangle and color the triangle with that color. When
> I get it working, I'll send you a picture. :)
Ok, I made a progress, it seems it's working. Script and picture
attached. You can compare to the mayavi plot above, it's almost
identical now. It took my some time playing with different parameters
of mpl to get here and I think it looks quite good. Still one can see
the artefacts though as John predicted, due to mpl not interpolating
the triangles.
Maybe I should use some graphics library directly, like Cairo, or
something similar? The mpl is also quite slow, I know that if I use
opengl directly, the plot is instant, so there must be some way
(unless the opengl is using the hardware to plot the triangles, which
it may well be).
Ondrej
From: Ondrej C. <on...@ce...> - 2009年05月22日 22:37:35
On Fri, May 22, 2009 at 7:06 AM, John Hunter <jd...@gm...> wrote:
> On Thu, May 21, 2009 at 9:31 PM, Ondrej Certik <on...@ce...> wrote:
>> Hi,
>>
>> I have a set of vertices in 2D as triples (x, y, val), where the x, y
>> are 2D coordinates and "val" is the scalar value of the finite element
>> solution, here is an example:
>>
>> In [54]: l.get_vertices()
>> Out[54]:
>> array([[ 0.00000000e+00, -1.00000000e+00, -2.22396971e-17],
>>    [ 1.00000000e+00, -1.00000000e+00, -1.64798730e-17],
>>    [ -1.00000000e+00,  0.00000000e+00,  8.09899023e-17],
>>    ...,
>>    [ 1.48437500e-01, -1.56250000e-02,  1.62359362e-01],
>>    [ 1.32812500e-01,  0.00000000e+00,  1.56012622e-01],
>>    [ 1.32812500e-01, -1.56250000e-02,  1.50562411e-01]])
>>
>>
>> and I also have a set of triangles that connect those points, here is
>> an example:
>>
>> In [55]: l.get_triangles()
>> Out[55]:
>> array([[  3, 5448,  29],
>>    [ 27, 5445,  28],
>>    [ 29,  28,  26],
>>    ...,
>>    [5499, 5498, 5479],
>>    [5510, 5493, 5491],
>>    [5513, 5508, 5491]], dtype=int32)
>>
>>
>> The triangles define the 2D domain. What is the best way to get this
>> plotted with mpl? Should I write a loop using the "plot" command, or
>> is there a better alternative? So far, I am using the contour command
>> and I feed it just with the vertices, here is the code:
>
> The best way is to define your triangles as an n length list of
> triangle vertices
>
> verts = [ ( (x00, y00), (x01, y01), (x02, y02)),
>         (x10, y10), (x11, y11), (x12, y12)),
>         ...
>  ]
>
> and have an equal length array of intensities for color mapping.
>
> vals = np.array(N_color_intensities)
>
> Then create a PolyCollection:
>
> import matplotlib.cm as cm
> import matplotlib.collections as collections
> col = collections.PolyCollection(verts)
> col.set_array(val)
> col.set_cmap(cm.hot)
> ax.add_collection(col)
>
> add_collection doesn't get the autoscaling limits, if I recall
> correctly, so you will probably want to do
>
> ax.set_xlim(xmin, xmax)
> ax.set_ylim(ymin,. ymax)
>
> See also:
>
> http://matplotlib.sourceforge.net/api/collections_api.html#matplotlib.collections.PolyCollection
> http://matplotlib.sourceforge.net/search.html?q=codex+PolyCollection
>
>
> Unfortunately, we do not currently have support for interpolating
> between adjacent polys in a PolyCollection, so the result may not look
> as nice as mayavis.
Thanks a lot John. I tried that and it does what I want. I just need
to convert and probably average my 3 different values at the 3
vertices of the triangle and color the triangle with that color. When
I get it working, I'll send you a picture. :)
On Fri, May 22, 2009 at 7:32 AM, Eric Carlson <eca...@en...> wrote:
> Here is an example using matplotlib.delaunay, which automatically
> returns the edges and triangules:
Thanks, that works too -- but it only plots the edges, right? I will
use that to plot the mesh, I need that as well.
For the FE solution, I'll use John's approach.
Ondrej
From: Adam M. <ram...@gm...> - 2009年05月22日 18:56:13
On Fri, May 22, 2009 at 09:20, John Hunter <jd...@gm...> wrote:
> Is there any reason you need to check the website, vs monitoring the
> announce list, or registering to be alerted from the sf site (there is
> a way to register to be alerted and I click the "alert all users
> monitoring this package" with each release, but I can't find the link
> right now).
Just in case I miss the release, MacPorts will alert me to a new
release being available. I suppose just me be lazy.
Cheers
Adam
From: Markus F. <fel...@gm...> - 2009年05月22日 15:15:18
Markus Feldmann schrieb:
> 
> to make some Plots, but my first Point lies on the beginning
> of my Plot. How to make some spaces ?
Ok i solved this by making,
 
self.subplot1.set_xlim(d[0]-abs(d[-1]-d[0])/100,d[-1]+abs(d[-1]-d[0])/100) 
 
self.subplot2.set_xlim(d[0]-abs(d[-1]-d[0])/100,d[-1]+abs(d[-1]-d[0])/100)
This make some more nice Spaces.
Regards Markus
From: Andrew S. <str...@as...> - 2009年05月22日 14:46:59
Adam Mercer wrote:
> On Thu, May 21, 2009 at 18:06, Andrew Straw <str...@as...> wrote:
> 
>> If there's a port of uscan for MacPorts (
>> http://manpages.debian.net/cgi-bin/man.cgi?query=uscan ) you could
>> simply use the debian watch file. It's contents are:
>>
>> version=3
>> http://sf.net/matplotlib/matplotlib-([0-9]+(?:\.[0-9]+)*)\.tar\.gz
> 
> That directory isn't listable, so won't work with the MacPorts version
> check infrastructure.
The uscan source can be seen here
http://www.google.com/codesearch/p?hl=en#_z_GL2ZoNPs/devscripts-2.9.26/uscan.pl&q=file:uscan.pl
It's pure perl and GPL, so I guess it should be fine to include
technically and legally with MacPorts.
-Andrew
From: Eric C. <eca...@en...> - 2009年05月22日 14:45:10
Here is an example using matplotlib.delaunay, which automatically 
returns the edges and triangules:
import matplotlib.delaunay as delaunay
import matplotlib.pyplot as pp
#generate points
npts=41
xpt=sp.random.random_sample(npts)
ypt=sp.random.random_sample(npts)
#create triangulation
circumcenters,edges,tri_points,tri_neighbors=delaunay.delaunay(xpt, ypt)
#plot using edges
pp.plot(xpt[edges.T],ypt[edges.T],'b-')
#following extracts same edges from triangles
# but does not worry about repeating edges
from numpy import vstack
my_edges=vstack( (tri_points[:,0:2],
 tri_points[:,1:],
 tri_points[:,2::-2]) )
#plot the edges extracted (possibly multiple times) from triangles
pp.plot(xpt[my_edges.T],ypt[my_edges.T],'r--')
From: Markus F. <fel...@gm...> - 2009年05月22日 14:40:06
John Hunter schrieb:
> On Fri, May 22, 2009 at 8:42 AM, Markus Feldmann <fel...@gm...> wrote:
>> I tried,
>> self.bars[0].set_x(x)
>> self.bars[0].set_y[y]
> 
> try self.bars[0].set_y(y)
> 
Thanks this corrects was my error.
I think you have eagle eyes. :-)
Regards markus
From: Markus F. <fel...@gm...> - 2009年05月22日 14:34:19
Hi All,
i am using,
 def draw(self,min,max):
 if not hasattr(self, 'subplot1'):
 self.subplot1 = self.figure.add_subplot(211)
 self.subplot1.grid(True)
 self.subplot2 = self.figure.add_subplot(212)
 self.subplot2.grid(True)
 a,b,c,d,e,f,g = self.compute(min)
 ymin_efg = numpy.real(numpy.amin((e,f,g)))
 ymax_efg = numpy.real(numpy.amax((e,f,g)))
 self.plots2 += self.subplot1.plot(d,a, color='red')
 self.plots2 += self.subplot1.plot(d,a+1, color='green')
 self.plots2 += self.subplot1.plot(d,c+2, color='blue')
 self.plots += self.subplot2.plot(d,numpy.abs(e),color='red')
 self.plots += self.subplot2.plot(d,numpy.abs(f),color='green')
 self.plots += self.subplot2.plot(d,numpy.abs(g),color='blue')
 
self.subplot1.legend((self.plots[0],self.plots[1],self.plots[2]),('Peak1','Peak2','Peak3'))
 self.subplot2.legend((self.plots[0],self.plots[1],self.plots[2]),
 ('abs(Wert von Peak1)','abs(Wert von Peak2)',
 'abs(Wert von Peak3)'))
 self.subplot1.set_ylim([-0.5, 3.5])
 self.subplot2.set_ylim([ymin_efg*1.2, ymax_efg*1.2])
to make some Plots, but my first Point lies on the beginning
of my Plot. How to make some spaces ?
Regards Markus
From: John H. <jd...@gm...> - 2009年05月22日 14:21:07
On Fri, May 22, 2009 at 8:42 AM, Markus Feldmann <fel...@gm...> wrote:
> I tried,
> self.bars[0].set_x(x)
> self.bars[0].set_y[y]
try self.bars[0].set_y(y)
JDH
From: John H. <jd...@gm...> - 2009年05月22日 14:20:12
On Fri, May 22, 2009 at 9:08 AM, Adam Mercer <ram...@gm...> wrote:
> On Thu, May 21, 2009 at 18:06, Andrew Straw <str...@as...> wrote:
>
>> If there's a port of uscan for MacPorts (
>> http://manpages.debian.net/cgi-bin/man.cgi?query=uscan ) you could
>> simply use the debian watch file. It's contents are:
>>
>> version=3
>> http://sf.net/matplotlib/matplotlib-([0-9]+(?:\.[0-9]+)*)\.tar\.gz
>
> That directory isn't listable, so won't work with the MacPorts version
> check infrastructure.
Is there any reason you need to check the website, vs monitoring the
announce list, or registering to be alerted from the sf site (there is
a way to register to be alerted and I click the "alert all users
monitoring this package" with each release, but I can't find the link
right now).
JDH
From: Adam M. <ram...@gm...> - 2009年05月22日 14:14:28
On Thu, May 21, 2009 at 18:06, Andrew Straw <str...@as...> wrote:
> If there's a port of uscan for MacPorts (
> http://manpages.debian.net/cgi-bin/man.cgi?query=uscan ) you could
> simply use the debian watch file. It's contents are:
>
> version=3
> http://sf.net/matplotlib/matplotlib-([0-9]+(?:\.[0-9]+)*)\.tar\.gz
That directory isn't listable, so won't work with the MacPorts version
check infrastructure.
Cheers
Adam
From: Todd P. <Tod...@li...> - 2009年05月22日 14:13:13
Chris, thank you very much for your reply. I encountered a related 
error, and was hoping you could help me understand this one too...
Using ipython -pylab I run the script below to generate a GUI, but 
when the GUI finishes running (after 3 button clicks), ipython crashes 
with the following error message: "Segmentation fault". This error 
does not occur if I remove the call to pyplot.close in 
myGUI.disconnect, nor does it occur if I use a key_press_event instead 
of a button_press_event.
Why is an error generated when I try to close the figure?
Why does this error occur for button_press_events but not 
key_press_events?
from numpy.random import rand
from matplotlib import pyplot
class myGUI:
 def __init__(self,x):
 self.fig = pyplot.gcf()
 self.n = 0
 self.connect()
 pyplot.plot(x)
 pyplot.show()
 def connect(self):
 self.cidbuttonpress = 
self.fig.canvas.mpl_connect('button_press_event', self.buttonpress)
 def disconnect(self):
 self.fig.canvas.mpl_disconnect(self.cidbuttonpress)
 pyplot.close(self.fig)
 def buttonpress(self,event):
 self.n += 1
 if self.n >=2:
 self.disconnect()
pyplot.figure()
obj = myGUI(rand(10))
On 22 May 2009, at 00:49, Christopher Barker wrote:
Todd Pataky wrote:
> I'm using the Enthought Python Distribution (EPD_Py25) and I enter
> IPython with the command: "ipython".
....
> This problem does not occur if I use EPD's PyLab (i.e. "ipython -
> pylab"). Does anyone know why?
because the whole point of the "pylab" flag to ipython is to tell
ipython to start up the MPL plotting stuff in separate thread so that it
can work like you want it to. If you don't' use that flag, then each
call to pyplot tries to start up a new app, ,but the old one is still
running, hence you problems.
ipython itself can be used for all sort of things that have nothing to
do with matplotlib, so that's not its default behavior.
Just use ipython -pylab if you want to do interactive plotting, that's
what it's for.
-Chris
From: John H. <jd...@gm...> - 2009年05月22日 14:06:12
On Thu, May 21, 2009 at 9:31 PM, Ondrej Certik <on...@ce...> wrote:
> Hi,
>
> I have a set of vertices in 2D as triples (x, y, val), where the x, y
> are 2D coordinates and "val" is the scalar value of the finite element
> solution, here is an example:
>
> In [54]: l.get_vertices()
> Out[54]:
> array([[ 0.00000000e+00, -1.00000000e+00, -2.22396971e-17],
> [ 1.00000000e+00, -1.00000000e+00, -1.64798730e-17],
> [ -1.00000000e+00, 0.00000000e+00, 8.09899023e-17],
> ...,
> [ 1.48437500e-01, -1.56250000e-02, 1.62359362e-01],
> [ 1.32812500e-01, 0.00000000e+00, 1.56012622e-01],
> [ 1.32812500e-01, -1.56250000e-02, 1.50562411e-01]])
>
>
> and I also have a set of triangles that connect those points, here is
> an example:
>
> In [55]: l.get_triangles()
> Out[55]:
> array([[ 3, 5448, 29],
> [ 27, 5445, 28],
> [ 29, 28, 26],
> ...,
> [5499, 5498, 5479],
> [5510, 5493, 5491],
> [5513, 5508, 5491]], dtype=int32)
>
>
> The triangles define the 2D domain. What is the best way to get this
> plotted with mpl? Should I write a loop using the "plot" command, or
> is there a better alternative? So far, I am using the contour command
> and I feed it just with the vertices, here is the code:
The best way is to define your triangles as an n length list of
triangle vertices
 verts = [ ( (x00, y00), (x01, y01), (x02, y02)),
 (x10, y10), (x11, y11), (x12, y12)),
 ...
 ]
and have an equal length array of intensities for color mapping.
 vals = np.array(N_color_intensities)
Then create a PolyCollection:
 import matplotlib.cm as cm
 import matplotlib.collections as collections
 col = collections.PolyCollection(verts)
 col.set_array(val)
 col.set_cmap(cm.hot)
 ax.add_collection(col)
add_collection doesn't get the autoscaling limits, if I recall
correctly, so you will probably want to do
 ax.set_xlim(xmin, xmax)
 ax.set_ylim(ymin,. ymax)
See also:
 http://matplotlib.sourceforge.net/api/collections_api.html#matplotlib.collections.PolyCollection
 http://matplotlib.sourceforge.net/search.html?q=codex+PolyCollection
Unfortunately, we do not currently have support for interpolating
between adjacent polys in a PolyCollection, so the result may not look
as nice as mayavis.
JDH
From: John H. <jd...@gm...> - 2009年05月22日 14:04:29
On Fri, May 22, 2009 at 8:09 AM, Markus Feldmann <fel...@gm...> wrote:
> i want to fill new xdata and new ydata to my bar() Elements.
>
> in the docu there is something written of,
> set_x()
> set_y()
>
> Is this of interest for me ?
Yes, there is also a set_width and set_height method. between the x,
y, width and height, you can update the rectangle position.
JDH
From: Markus F. <fel...@gm...> - 2009年05月22日 14:03:53
Markus Feldmann schrieb:
> in the docu there is something written of,
> set_x()
> set_y()
> 
> Is this of interest for me ?
> 
> My xdata and ydata are 1D Vectors like,
> x = [1, 2, 4, 2, ...]
> y = [1, 0, 0, 1, ...]
> 
I tried,
self.bars[0].set_x(x)
self.bars[0].set_y[y]
where self.bars is a List containg my bar() Elements.
But this doesn't work and results in an error,
TypeError: 'instancemethod' object is unsubscriptable
Any Ideas ?
regards Markus
From: Markus F. <fel...@gm...> - 2009年05月22日 13:10:12
John Hunter schrieb:
> 
> http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.Rectangle
> 
> Those docs will show you all the properties (alpha, antialiased,
> ...facecolor, etc...) Each property has a link to the setter method.
> So I advise something like
> 
> # the names "self.rectangles" is better than "self.bar" IMO since
> it describe whats kinds of mpl
> # object it are referring to
> self.rectangles = self.ax2.bar(something)
> for rectangle in self.rectangles:
> rectangle.set_alpha(0.4)
> rectangle.set_facecolor('green')
> 
Thanks for your Answer,
i want to fill new xdata and new ydata to my bar() Elements.
in the docu there is something written of,
set_x()
set_y()
Is this of interest for me ?
My xdata and ydata are 1D Vectors like,
x = [1, 2, 4, 2, ...]
y = [1, 0, 0, 1, ...]
Regards Markus
From: John H. <jd...@gm...> - 2009年05月22日 11:51:05
On Fri, May 22, 2009 at 5:17 AM, Markus Feldmann <fel...@gm...> wrote:
> Hi All,
>
> i am in need of set the properties of my bar() Element,
> by using a slider.
>
> For plots this looks like this:
> self.plot = self.subplot1.plot(x,y)
> setp(self.plot, xdata=new_x, ydata=new_y)
>
> How to do this with this,
> self.bar = self.subplot2.bar(x,y)
It depends on what kinds of properties you want to set. For example,
you could set the facecolor with
 plt.setp(self.bar, facecolor='red')
But I would advise you against this method of coding -- it's great for
simple interactive command line stuff, eg at the ipython prompt, but
it sounds like you are doing something a little more sophisticated and
would be better off plunging into the API. For example, you are
calling the matplotlib.axes.Axes.bar method (since your subplot2
instance is a Subplot which is an Axes subclass). So start with the
docs for Axes.bar
 http://matplotlib.sourceforge.net/api/axes_api.html#matplotlib.axes.Axes.bar
You will see in the docstring that it says it returns a sequence of
Rectangle and has a link to the matplotlib.patches.Rectangle docs
 http://matplotlib.sourceforge.net/api/artist_api.html#matplotlib.patches.Rectangle
Those docs will show you all the properties (alpha, antialiased,
...facecolor, etc...) Each property has a link to the setter method.
So I advise something like
 # the names "self.rectangles" is better than "self.bar" IMO since
it describe whats kinds of mpl
 # object it are referring to
 self.rectangles = self.ax2.bar(something)
 for rectangle in self.rectangles:
 rectangle.set_alpha(0.4)
 rectangle.set_facecolor('green')
JDH
From: Markus F. <fel...@gm...> - 2009年05月22日 10:18:14
Hi All,
i am in need of set the properties of my bar() Element,
by using a slider.
For plots this looks like this:
self.plot = self.subplot1.plot(x,y)
setp(self.plot, xdata=new_x, ydata=new_y)
How to do this with this,
self.bar = self.subplot2.bar(x,y)
???
Any Hints ?
Regards Markus
From: Sebastian B. <web...@th...> - 2009年05月22日 07:01:23
Attachments: signature.asc
Thomas Pfaff wrote:
> ... ImageMagick just puts a bitmap representation of the
> image into the EMF-file ... I want ... vectors, though.
hey thomas!
i see. perhaps xfig could then help you, it has an export to emf feature
(and can import ps files, see for example
http://www.thamnos.de/computer-corner/latex/ ). and at least when
exporting pdf files, they are in a vector format.
best,
sebastian.
From: Ondrej C. <on...@ce...> - 2009年05月22日 02:32:04
Attachments: mpl1.png mayavi.png
Hi,
I have a set of vertices in 2D as triples (x, y, val), where the x, y
are 2D coordinates and "val" is the scalar value of the finite element
solution, here is an example:
In [54]: l.get_vertices()
Out[54]:
array([[ 0.00000000e+00, -1.00000000e+00, -2.22396971e-17],
 [ 1.00000000e+00, -1.00000000e+00, -1.64798730e-17],
 [ -1.00000000e+00, 0.00000000e+00, 8.09899023e-17],
 ...,
 [ 1.48437500e-01, -1.56250000e-02, 1.62359362e-01],
 [ 1.32812500e-01, 0.00000000e+00, 1.56012622e-01],
 [ 1.32812500e-01, -1.56250000e-02, 1.50562411e-01]])
and I also have a set of triangles that connect those points, here is
an example:
In [55]: l.get_triangles()
Out[55]:
array([[ 3, 5448, 29],
 [ 27, 5445, 28],
 [ 29, 28, 26],
 ...,
 [5499, 5498, 5479],
 [5510, 5493, 5491],
 [5513, 5508, 5491]], dtype=int32)
The triangles define the 2D domain. What is the best way to get this
plotted with mpl? Should I write a loop using the "plot" command, or
is there a better alternative? So far, I am using the contour command
and I feed it just with the vertices, here is the code:
 vert = lin.get_vertices()
 from numpy import min, max, linspace
 from matplotlib.mlab import griddata
 import matplotlib.pyplot as plt
 # make up data.
 #npts = int(raw_input('enter # of random points to plot:'))
 npts = 200
 x = vert[:, 0]
 y = vert[:, 1]
 z = vert[:, 2]
 # define grid.
 xi = linspace(min(x), max(x), 100)
 yi = linspace(min(y), max(y), 100)
 # grid the data.
 zi = griddata(x,y,z,xi,yi)
 # contour the gridded data, plotting dots at the nonuniform data points.
 CS = plt.contour(xi,yi,zi,15,linewidths=0.5,colors='k')
 CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.jet)
 plt.colorbar() # draw colorbar
 plt.title('Solution (%d points)' % npts)
The output of which is attached. It looks ugly, because mpl doesn't
have enough information about the domain. Mayavi can use this
information with this script:
 vert = lin.get_vertices()
 triangles = lin.get_triangles()
 from numpy import zeros
 from enthought.mayavi import mlab
 x = vert[:, 0]
 y = vert[:, 1]
 z = zeros(len(y))
 t = vert[:, 2]
 # the off screen rendering properly works only with VTK-5.2 or above:
 mlab.options.offscreen = True
 s = mlab.triangular_mesh(x, y, z, triangles, scalars=t)
 mlab.view(azimuth=90, elevation=180)
the output of which is attached. Mayavi is good, but it's a little
overkill for this purpose, as it takes a while to start etc. I want to
use it inside the Sage notebook, where matplotlib is faster and takes
less memory. Also it's way easier to install (e.g. no vtk, and
fiddling with os mesa).
Thanks for any ideas.
Ondrej

Showing 21 results of 21

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