[Matplotlib-users] Newbie question
Hi all
I'm a new user to matplotlib, and I'm having a little difficulty with
something I feel must be basic. When I plot our data, I'm using a canvas
that is 4"x4" at 128 DPI and saving the canvas as a png. Here's the
basics of the code:
imageWidth = 4
imageHeight = 4
DPI = 128
figure1 = plt.figure(figsize=(imageWidth,imageHeight))
plt.axis("off")
plt.tricontourf(theTriangulation,
modelData,
theLookupTable.N,
cmap=theLookupTable)
canvas = FigureCanvasAgg(figure1)
canvas.print_figure(prefix + ".png", dpi=DPI)
The png is 512x512 as I would expect, but the contoured image doesn't
fill the whole image. How do I tell the library to map the plotted are
to the entire canvas and not leave a border around the rendered image?
Thanks
Howard
--
Howard Lander <mailto:[email protected]>
Senior Research Software Developer
Renaissance Computing Institute (RENCI) <http://www.renci.org>
The University of North Carolina at Chapel Hill
Duke University
North Carolina State University
100 Europa Drive
Suite 540
Chapel Hill, NC 27517
919-445-9651
--
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Newbie question
On 11/9/11 11:13 AM, Joe Kington wrote: On Wed, Nov 9, 2011 at 10:07 AM, Howard <mailto:[email protected]>> wrote: Hi all I'm a new user to matplotlib, and I'm having a little difficulty with something I feel must be basic. When I plot our data, I'm using a canvas that is 4"x4" at 128 DPI and saving the canvas as a png. Here's the basics of the code: imageWidth = 4 imageHeight = 4 DPI = 128 figure1 = plt.figure(figsize=(imageWidth,imageHeight)) plt.axis("off") plt.tricontourf(theTriangulation, modelData, theLookupTable.N, cmap=theLookupTable) canvas = FigureCanvasAgg(figure1) canvas.print_figure(prefix + ".png", dpi=DPI) The png is 512x512 as I would expect, but the contoured image doesn't fill the whole image. How do I tell the library to map the plotted are to the entire canvas and not leave a border around the rendered image? You need to make an axis that fills up the entire figure. By default, axes don't fill up the entire figure to leave room for tick labels, axis lables, titles, etc. Try something like: import matplotlib as plt dpi = 128 fig = plt.figure(figsize=(4,4)) # Specifies an axis at 0, 0 with a width and height of 1 (the full width of the figure) ax = fig.add_axes([0,0,1,1]) ax.tricontourf(...) fig.savefig('output.png', dpi=dpi) Hope that helps, -Joe Hi Joe That did it! Thanks much. Can I also turn off the tick marks on the new axis? Howard -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Newbie question
On 11/9/11 11:20 AM, Howard wrote: On 11/9/11 11:13 AM, Joe Kington wrote: On Wed, Nov 9, 2011 at 10:07 AM, Howard <mailto:[email protected]>> wrote: Hi all I'm a new user to matplotlib, and I'm having a little difficulty with something I feel must be basic. When I plot our data, I'm using a canvas that is 4"x4" at 128 DPI and saving the canvas as a png. Here's the basics of the code: imageWidth = 4 imageHeight = 4 DPI = 128 figure1 = plt.figure(figsize=(imageWidth,imageHeight)) plt.axis("off") plt.tricontourf(theTriangulation, modelData, theLookupTable.N, cmap=theLookupTable) canvas = FigureCanvasAgg(figure1) canvas.print_figure(prefix + ".png", dpi=DPI) The png is 512x512 as I would expect, but the contoured image doesn't fill the whole image. How do I tell the library to map the plotted are to the entire canvas and not leave a border around the rendered image? You need to make an axis that fills up the entire figure. By default, axes don't fill up the entire figure to leave room for tick labels, axis lables, titles, etc. Try something like: import matplotlib as plt dpi = 128 fig = plt.figure(figsize=(4,4)) # Specifies an axis at 0, 0 with a width and height of 1 (the full width of the figure) ax = fig.add_axes([0,0,1,1]) ax.tricontourf(...) fig.savefig('output.png', dpi=dpi) Hope that helps, -Joe Hi Joe That did it! Thanks much. Can I also turn off the tick marks on the new axis? Howard For the sake of reply, this seems to work to get rid of the tick marks: ax.tick_params(axis="both", length=0, width=0) Thanks Howard -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- RSA(R) Conference 2012 Save $700 by Nov 18 Register now http://p.sf.net/sfu/rsa-sfdev2dev1___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Hardware rendering with tricontourf
Hi all
I'm rendering some images with about 3.5 million triangles into a
512x512 png file using tricontourf. I'm running this in a virtual
machine, and I'm pretty sure that there is no graphics rendering
hardware being used. Is it possible, assuming the hardware was
available, to make tricontourf use the rendering hardware? Will that
happen by default?
Here's the relevant portion of the code.
figure1 = plt.figure(figsize=(imageWidth,imageHeight))
theTriangulation.set_mask(mask)
plt.axis("off")
# This makes sure the figure fills the canvas
ax = figure1.add_axes([0,0,1,1])
# This turns off the tick marks of the axis we added.
ax.axis("off")
plt.tricontourf(theTriangulation,
modelData,
theLookupTable.N,
norm=theNorm,
antialiased=False,
cmap=theLookupTable)
canvas = FigureCanvasAgg(figure1)
canvas.print_figure(fileName, dpi=DPI)
Thanks
Howard
--
Howard Lander <mailto:[email protected]>
Senior Research Software Developer
Renaissance Computing Institute (RENCI) <http://www.renci.org>
The University of North Carolina at Chapel Hill
Duke University
North Carolina State University
100 Europa Drive
Suite 540
Chapel Hill, NC 27517
919-445-9651
--
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d___
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Hardware rendering with tricontourf
On 1/27/12 3:39 AM, Ian Thomas wrote: On 26 January 2012 19:36, Howard <mailto:[email protected]>> wrote: I'm rendering some images with about 3.5 million triangles into a 512x512 png file using tricontourf. I'm running this in a virtual machine, and I'm pretty sure that there is no graphics rendering hardware being used. Is it possible, assuming the hardware was available, to make tricontourf use the rendering hardware? Will that happen by default? You are correct, there is no graphics hardware rendering. Rendering is controlled by the various matplotlib backends, and to my knowledge there are no backends currently available that use hardware rendering. There has been some work done on an OpenGL backend, but I am not sure of the status of this. The last time I checked it was pretty experimental. Perhaps someone involved with it can comment on its current status. Ian Thomas Ian Thanks very much for the reply. If it helps whoever is doing the OpenGL backend, I may be able to play with it a bit. Howard -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Hardware rendering with tricontourf
Hi Nicolas Thanks for the post. I'm going to finish optimizing all of the non-rendering pieces of my code, then I'll see if trying the hardware rendering makes sense. Right now I am software rendering 3.5 million triangles in about 5 seconds, but the setup (masking etc) is taking about 40. When I get the setup lower (which I think I will), I'll get back to you about this. Thanks again Howard On 1/29/12 7:43 AM, Nicolas Rougier wrote: Thanks for posting the link to glumpy. As Benjamin explained, glumpy servers as a testbed for various technics that could be implemented later in matplotlib. The main problem today is that if you want to benefit from hardware acceleration, you have to use some GL features that are not compatible with he whole matplotlib framework (and we need to ensure some degree of compatibilty). I do not have yet a clean solution and I'm still experimenting. For your tricontourf problem, I think it might be solved quite easily with the proper GL shader but I would need a complete (and basic) matplotlib script example to check if this is actually the case. Nicolas On Jan 27, 2012, at 23:12 , Benjamin Root wrote: On Fri, Jan 27, 2012 at 10:06 AM, Howard <mailto:[email protected]>> wrote: On 1/27/12 3:39 AM, Ian Thomas wrote: On 26 January 2012 19:36, Howard mailto:[email protected]>> wrote: I'm rendering some images with about 3.5 million triangles into a 512x512 png file using tricontourf. I'm running this in a virtual machine, and I'm pretty sure that there is no graphics rendering hardware being used. Is it possible, assuming the hardware was available, to make tricontourf use the rendering hardware? Will that happen by default? You are correct, there is no graphics hardware rendering. Rendering is controlled by the various matplotlib backends, and to my knowledge there are no backends currently available that use hardware rendering. There has been some work done on an OpenGL backend, but I am not sure of the status of this. The last time I checked it was pretty experimental. Perhaps someone involved with it can comment on its current status. Ian Thomas Ian Thanks very much for the reply. If it helps whoever is doing the OpenGL backend, I may be able to play with it a bit. Howard That would be the Glumpy project. http://code.google.com/p/glumpy/ As stated in an email response a while back, glumpy is intended to be a testbed for developing the OpenGL backend for future inclusion into matplotlib. Cheers! Ben Root -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Tricontourf with a triangulation
Hi all I'm using tricontourf with a triangulation object to draw a surface. For debugging purposes, I'd like to draw just the unfilled triangles. Is there a simple way to do this? Thanks Howard -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Tricontourf with a triangulation
Hmm, on further review, it looks like this is what triplot does! I'll give it a try... On 2/13/12 3:30 PM, Howard wrote: Hi all I'm using tricontourf with a triangulation object to draw a surface. For debugging purposes, I'd like to draw just the unfilled triangles. Is there a simple way to do this? Thanks Howard -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- Howard Lander <mailto:[email protected]> Senior Research Software Developer Renaissance Computing Institute (RENCI) <http://www.renci.org> The University of North Carolina at Chapel Hill Duke University North Carolina State University 100 Europa Drive Suite 540 Chapel Hill, NC 27517 919-445-9651 -- Try before you buy = See our experts in action! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-dev2___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] multiple lines
Sorry for the newbie question, how do you plot one x with multiple ys. In below data, x column is followed by 5 y columns: Many thanks! Howard 2 1.e+00 6.6232e-02 9.9392e-03 2.2992e-02 3.8111e-07 3 6.3664e-01 1.0269e-01 7.9107e-03 1.8254e-02 1.1391e-07 4 2.7590e-01 4.9783e-02 6.2644e-03 1.0943e-02 5.8480e-08 5 1.6550e-01 2.3269e-02 4.7482e-03 8.4312e-03 5.8239e-08 6 1.1590e-01 1.7234e-02 3.8567e-03 8.7010e-03 4.5506e-08 7 7.4337e-02 1.1662e-02 3.3756e-03 8.0889e-03 4.0900e-08 8 5.7775e-02 1.0917e-02 2.8980e-03 6.9654e-03 3.7520e-08 9 4.7310e-02 1.1869e-02 2.5929e-03 5.8326e-03 3.4745e-08 10 3.9591e-02 1.1301e-02 2.4691e-03 5.2749e-03 3.2126e-08 11 3.6517e-02 1.0755e-02 2.3121e-03 4.8631e-03 3.7942e-08 12 3.2872e-02 9.8306e-03 2.1692e-03 4.6281e-03 3.2358e-08 13 3.1235e-02 9.1704e-03 2.0419e-03 4.3928e-03 3.1479e-08 14 2.9528e-02 8.6926e-03 1.9364e-03 4.1360e-03 3.5639e-08 15 2.7895e-02 8.3080e-03 1.8475e-03 3.9015e-03 3.0486e-08 16 2.6440e-02 7.9610e-03 1.7776e-03 3.6790e-03 3.0307e-08 17 2.5259e-02 7.6345e-03 1.6984e-03 3.4743e-03 3.1805e-08 18 2.4064e-02 7.3267e-03 1.6341e-03 3.2848e-03 3.0188e-08 19 2.3171e-02 7.0284e-03 1.5821e-03 3.1098e-03 2.7565e-08 20 2.2317e-02 6.7322e-03 1.5247e-03 2.9475e-03 2.7009e-08 --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- -- ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] multiple lines
Thanks alot, Alan, Angus, Ben, Eric and Malte, for the tips and the varieties. Matplotlib is awesome! Howard Sun, Ph.D. NVIDIA CORP. 2701 San Tomas Expressway Santa Clara, CA 95050 T (408) 566-5036 F (408) 486-8207 -Original Message- From: Eric Firing [mailto:[email protected]] Sent: Tuesday, June 01, 2010 7:07 PM To: [email protected] Subject: Re: [Matplotlib-users] multiple lines On 06/01/2010 02:47 PM, Benjamin Root wrote: > Howard, > > Are you trying to plot 4 lines with the same y-axis or with two or more > y-axes? I only ask because the values of your 5th column are many > orders of magnitude smaller than the values of the other ys. > > If you want multiple y-axes on the same plot, then you might want to > look at Parasite Axes. If not, then you can very simply plot this like > so (assuming that 'data' is a 2-D numpy array). > > import matplotlib.pyplot as plt > > plt.plot(data[:, 0], data[:, 1]) > plt.plot(data[:, 0], data[:, 2]) > plt.plot(data[:, 0], data[:, 3]) > plt.plot(data[:, 0], data[:, 4]) > > plt.show() > > I am sure that my 4 plot statements can be simplified, but I can't > verify that right now. import numpy as np import matplotlib.pyplot as plt x = np.arange(2, 5, 0.3) y = np.random.randn(len(x), 4) # dummy data for illustration plt.plot(x, y) So with the data array as above, it would be plt.plot(data[:,0], data[:, 1:]) Eric > > I hope that helps. > > Ben Root -- ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users --- This email message is for the sole use of the intended recipient(s) and may contain confidential information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. --- -- ___ Matplotlib-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matplotlib-users
