Re: [Matplotlib-users] How to start when you don't know what to do
Hi Steven, First let me say, your question is great. It is humble and great too. Then, I would say, just do it. Sorry for the cliché, but programming is a lot of trial and error. If you don't do, you will not make errors, and you will not learn. But lucky for you, you live in the age of Internet. So, you have this list, physics forums, and places like stackoverflow. Asking the list is not a bad idea. Search isn't also. A lot of times, I started writing code, and then realized I don't know even how to formulate the question. So, I just googled and browsed stackoverflow, until I found a way to ask the question. Many times, I realized I already know most of the answer and just needed a little help. This help came from the list or from people in stackoverflow (which by the way rewards for asking good questions too! you'd get a lot of upvoted for that). If you are newbie - and also if you aren't - and you still don't know IPython - use IPython! It makes the learning curve of Python way smoother. It gives you documentation in very very handy way, and pressing TAB [1] shows you what every object can do (in other words, OO terminology, which methods the object has). And finally, be patient. Any significant learning you do, takes time. Don't expect to do fancy graphs right away. Man, I had plotted about 120 alone in my master thesis. Luckily, I already trained during my courses before, although the assignments were supposed to be done in Matlab (yuck!), I insisted doing everything in Python two. And you know what? 2 years later when I look at my codes written back then, I think eww... I could that better, and this too!. It will happen to you too. You will start awkward, not sure, with many ugly hacks. And then suddenly, after 1-2 years, you will realize you speak Python, and you know how to read the very good documentation of matplotlib. It will happen to you too. I am also adding a link to a nice blog I follow about numpy and matplotlib: http://glowingpython.blogspot.com Good luck, and enjoy the journey. Oz [1] this feature is also available also in a normal Python session under certain conditions ... -- Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS and more. Get SQL Server skills now (including 2012) with LearnDevNow - 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only - learn more at: http://p.sf.net/sfu/learnmore_122512 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] about show()
Hi MicDup, Try using in your script show(mainloop=True) - if your matplotlib is 1.0.0 Cheers, -- Oz Nahum --- Gentlmen! You can't fight in here, this is the War Room! President Merkin Muffley (Peter Sellers, Dr. Strangelove) -- Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] recipes in the docs
A small suggestion to the examples ... I really like the new subplot mechanism, so I tried it: fig, (ax1, ax2, ax3, ax4) = plt.subplots(2, 2, sharex=True, sharey=True) And it actually gave me the following error: Traceback (most recent call last): File tes.py, line 21, in module f, (ax1, ax2, ax3, ax4) = subplots(2, 2, sharey=True) ValueError: need more than 2 values to unpack I got over with with a small modification: f, ((ax1,ax2),(ax3,ax4)) = subplots(2, 2, sharey=True) Which now worked ! Cheers, -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- The Next 800 Companies to Lead America's Growth: New Video Whitepaper David G. Thomson, author of the best-selling book Blueprint to a Billion shares his insights and actions to help propel your business during the next growth cycle. Listen Now! http://p.sf.net/sfu/SAP-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Adjusting subplot parameters
Hallo Nils, I always create my plots in the following way: figprops = dict(figsize=(6.5, 7.5), dpi=1200) fig = plt.figure(**figprops) clf() adjustprops = dict(left=0.08, bottom=0.08, right=0.965, top=0.94, wspace=0.13, hspace=0.37) fig.subplots_adjust(**adjustprops) ... savefig('all.pdf',papertype='a4', orientation='portrait') Good to know someone close is also using it :-) Viele Gruesse aus Tuebingen ;-) -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Nokia and ATT present the 2010 Calling All Innovators-North America contest Create new apps games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] empty xticklabel before plotting ...
Hi Everyone, I don't like the default scientific formatting in matplotlib, IMHO the format of having a zero after the exponent is a waste of space in my opinion ... What I mean is that mpl is writing zero as: 0.0e+00 or 1.2e-03. IMHO it would suffice just to do 0.0 and 1.2e-3, which take less space and looks better (again, imho). In any case, I would like to access the strings of the yticklables in my plots and I discovered I can do the following: setp(axs[2].set_yticklabels(['0.0','2.0E-4','4.0E-4','6.0E-4','8.0E-4','1.0E-3','1.2E-3'])) Which works, but forces me to first look at the output and the redraw everything with manually feeding the values. if there is a way to loop on this text values before plotting I will be happy to know. I tried doing this: In [1]: from pylab import * In [2]: f=figure() In [3]: ax=f.add_subplot() In [4]: ax.plot([1,2,3,4,5]) --- AttributeErrorTraceback (most recent call last) /home/oz/ipython console in module() AttributeError: 'NoneType' object has no attribute 'plot' In [5]: ax=f.add_subplot(111) In [6]: ax.plot([1,2,3,4,5]) Out[6]: [matplotlib.lines.Line2D object at 0x95ecdcc] In [7]: a=ax.get_xticklabels() In [8]: a[0].get_text() Out[8]: '' In [9]: draw() In [10]: a[0].get_text() In [10]: a[0].get_text() Out[10]: '' In [11]: show() KeyboardInterrupt: In [12]: a[0].get_text() Out[12]: u'0.0 As can be seen, the text string is empty before calling show, which is forcing me to show the image . Is there a way to access these labales with out calling show() ? Thanks in advance, -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] empty xticklabel before plotting ...
Hi Ryan, Thanks for your answer. However, I don't understand from the existing documentation how to use tickers. In the past I used the following method: class SciFormatter(Formatter): def __call__(self, x, pos=None): return %1.1e % x axs.yaxis.set_major_formatter(SciFormatter()) This still does not allow me to get read of the zeros that matplotlib coherces . I would like to manipulate the strings of the tick labels directly. I know it's not ideal, but I it should work. If I could access the label 1.1E+01, I could tell python just to take label[:-2] and glue it to label[-1], which will give me 1.1E+1 I would be greatful if someone showed me how to access that string. Cheers, Oz On Thu, Sep 23, 2010 at 3:37 PM, Ryan May rma...@gmail.com wrote: On Thu, Sep 23, 2010 at 3:49 AM, Oz Nahum nahu...@gmail.com wrote: Hi Everyone, I don't like the default scientific formatting in matplotlib, IMHO the format of having a zero after the exponent is a waste of space in my opinion ... What I mean is that mpl is writing zero as: 0.0e+00 or 1.2e-03. IMHO it would suffice just to do 0.0 and 1.2e-3, which take less space and looks better (again, imho). SNIP As can be seen, the text string is empty before calling show, which is forcing me to show the image . Is there a way to access these labales with out calling show() ? What you want is to set a custom formatter: http://matplotlib.sourceforge.net/api/ticker_api.html import matplotlib.pyplot as plt f = plt.figure() ax = f.add_subplot(111) ax.plot([1,2,3,4,5]) # Formats ticks on the xaxis with the %.2g format string ax.xaxis.set_major_formatter(plt.FormatStrFormatter('%.2g')) plt.show() If you can't get what you want using a format string, you can write a function that does what you want can create a formatter from that using FuncFormatter. Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] empty xticklabel before plotting ...
Hi Every, Hi Ryan I finally solved this issue, which bothered me very long. I managed to make a nicer scientific formatting on the xticks ! from pylab import * import numpy as N from matplotlib.ticker import Formatter,FuncFormatter import os #class to produce scientific format numbering class SciFormatter(Formatter): def __call__(self, x, pos=None): return %1.e % x class NiceSciFormatter(Formatter): def __call__(self, x, pos=None): a=%1.1E % x a=a[:5]+a[-1] return a fig=figure() ax=fig.add_subplot(111) y=[.0001,.0002,.0003,.0004,.0005] x=[1,2,3,4,5] ax.plot(x,y) ax.yaxis.set_major_formatter(NiceSciFormatter()) show() Cheers , Oz -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Nokia and ATT present the 2010 Calling All Innovators-North America contest Create new apps games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] empty xticklabel before plotting ...
Hi Ryan, Thanks again, Well your solution is also working. I get very similar results with class NiceSciFormatter(Formatter): def __call__(self, x, pos=None): a=%1.1E % x a=a[:5]+a[-1] return a It seems though that your solution enables more fine tuning ! Cheers, Oz On Thu, Sep 23, 2010 at 5:10 PM, Ryan May rma...@gmail.com wrote: On Thu, Sep 23, 2010 at 8:52 AM, Oz Nahum nahu...@gmail.com wrote: Hi Ryan, Thanks for your answer. However, I don't understand from the existing documentation how to use tickers. In the past I used the following method: class SciFormatter(Formatter): def __call__(self, x, pos=None): return %1.1e % x axs.yaxis.set_major_formatter(SciFormatter()) This still does not allow me to get read of the zeros that matplotlib coherces . I would like to manipulate the strings of the tick labels directly. I know it's not ideal, but I it should work. If I could access the label 1.1E+01, I could tell python just to take label[:-2] and glue it to label[-1], which will give me 1.1E+1 I would be greatful if someone showed me how to access that string. Why not just format the number yourself? import matplotlib.pyplot as plt import numpy as np def format(x, pos=None): if x == 0.0: exp = 0 else: exp = int(np.log10(np.abs(x))) mant = x / 10**exp return '%.2fE%+d' % (mant, exp) f = plt.figure() ax = f.add_subplot(111) data = np.array([1,2,3,4,5]) / 100. ax.plot(data, np.arange(len(data))) ax.xaxis.set_major_formatter(plt.FuncFormatter(format)) plt.show() Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Nokia and ATT present the 2010 Calling All Innovators-North America contest Create new apps games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] how to put non-latin text on plots?
Hi Everyone, Not really related to my every day work, but I was asking myself how to put non latin letters, like arabic or hebrew on plots. I found a way to put german umlauts and ß but this is only a very partial solution. It would be cool to know how to over come this. My code to work with umlauts is: #!/usr/bin/env python # -*- coding: utf-8 -*- import matplotlib.pyplot as plt import numpy as np def format(x, pos=None): if x == 0.0: exp = 0 else: exp = int(np.log10(np.abs(x))) mant = x / 10**exp return '%.1fE%+d' % (mant, exp) f = plt.figure() ax = f.add_subplot(111) data = np.array([1,2,3,4,5]) / 100. ax.plot(data, np.arange(len(data))) ax.xaxis.set_major_formatter(plt.FuncFormatter(format)) ax.yaxis.set_major_formatter(plt.FuncFormatter(format)) ax.text(0.03,0.5,Umlauts äüöß+ u\u00e4) plt.show() If I include arabic or hebrew letters I get Bricks displays. Thanks in advance, Oz -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Nokia and ATT present the 2010 Calling All Innovators-North America contest Create new apps games for the Nokia N8 for consumers in U.S. and Canada $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store http://p.sf.net/sfu/nokia-dev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] quiver units
Hi Everyone, I'm trying to make a quiver plot using the example in examples collection. The documentation says that I can define the arrow units as: ** *units*: [‘width’ | ‘height’ | ‘dots’ | ‘inches’ | ‘x’ | ‘y’ | ‘xy’]so I did: from pylab import * from numpy import ma X,Y = meshgrid( arange(0,2*pi,.2),arange(0,2*pi,.2) ) U = cos(X) V = sin(Y) figure() M = sqrt(pow(U, 2) + pow(V, 2)) Q = quiver( X, Y, U, V, M, units='x', pivot='tip', width=0.022, scale=1/0.15) Q = quiver( X, Y, U, V, M, units='xy', pivot='tip', width=0.022, scale=1/0.15) qk = quiverkey(Q, 0.9, 1.05, 1, r'$1 \frac{m}{s}$', labelpos='E', fontproperties={'weight': 'bold'}) plot(X, Y, 'k.') axis([-1, 7, -1, 7]) title(scales with x view; pivot='tip') show() When I actually try the option 'xy' I get the following error: Exception in Tkinter callback Traceback (most recent call last): File /usr/lib/python2.6/lib-tk/Tkinter.py, line 1413, in __call__ return self.func(*args) File /usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py, line 212, in resize self.show() File /usr/lib/pymodules/python2.6/matplotlib/backends/backend_tkagg.py, line 215, in draw FigureCanvasAgg.draw(self) File /usr/lib/pymodules/python2.6/matplotlib/backends/backend_agg.py, line 314, in draw self.figure.draw(self.renderer) File /usr/lib/pymodules/python2.6/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/figure.py, line 773, in draw for a in self.axes: a.draw(renderer) File /usr/lib/pymodules/python2.6/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/axes.py, line 1735, in draw a.draw(renderer) File /usr/lib/pymodules/python2.6/matplotlib/artist.py, line 46, in draw_wrapper draw(artist, renderer, *args, **kwargs) File /usr/lib/pymodules/python2.6/matplotlib/quiver.py, line 436, in draw self._init() File /usr/lib/pymodules/python2.6/matplotlib/quiver.py, line 425, in _init trans = self._set_transform() File /usr/lib/pymodules/python2.6/matplotlib/quiver.py, line 481, in _set_transform raise ValueError('unrecognized units') ValueError: unrecognized units Can someone point to where am I mistaken ? Is it a mistake in the documentation ? Thanks, -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] colorbar questions ...
Hi Ben, Thanks for your reply it sure helps. My awkward work around until now was to put before the colorbar: matplotlib.rc('axes',edgecolor='w') and the return it to matplotlib.rc('axes',edgecolor='k'). Does some one knows how to increase the distance between the color bar and the X-axis ? Now I noticed that the color bar hides the xlabel Thanks again, Oz I agree, Colorbar isn't the most elegant of objects and is probably due for some improvements. I am sure there is probably a better way to do what you have done, but I am not familiar with it. Anyway, to get rid of the box around the colorbar, the colorbar object has a member attribute called outline which you can set_visible(False). a = plt.colorbar() a.outline.set_visible(False) Should do the trick for that part. I hope this helps! Ben Root -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing. http://p.sf.net/sfu/novell-sfdev2dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] colorbar questions ...
Hi Everyone again, So, with the weekend comes some time to think and I found an answer to another question of mine. I know now how to remove xticks in colorbar, and I also know how to customize the widths of the lines in the color bar. import matplotlib import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt from pylab import * matplotlib.rcParams['xtick.direction'] = 'out' matplotlib.rcParams['ytick.direction'] = 'out' delta = 0.025 x = np.arange(-3.0, 3.0, delta) y = np.arange(-2.0, 2.0, delta) X, Y = np.meshgrid(x, y) Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) # difference of Gaussians Z = 10.0 * (Z2 - Z1) # Create a simple contour plot with labels using default colors. The # inline argument to clabel will control whether the labels are draw # over the line segments of the contour, removing the lines beneath # the label plt.figure() CS = plt.contour(X, Y, Z) plt.clabel(CS, inline=1, fontsize=10,inlinespacing=50) a=plt.colorbar() ticks = a.ax.get_xticklines() lines = a.ax.get_ygridlines() children=a.ax.get_children() children=a.ax.get_children() children[4].set_linewidths([12,12,12,12,12,12]) for tick in ticks: setp(tick, []) plt.title('Customize colorbar') I hope someone finds that useful. And someone is still following my monologue, my question, how to remove the axes around the colorbar, or at least changed the to be non-visible, still stands... Thanks, Oz -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] colorbar questions ...
Hi Everyone, First I must cryout a little bit :-) Why colorbar is always so tricky ??? I'm trying to fine tune the colorbar of my contour plots. I would like to do the following things: 1) remove the box around it 2) hide the xticks 3) make the lines with the indicating colors with custom widths so far I succeeded only with task 2 ! here is what I did: cs=axs[4].contour(x,y,phcr1t,linestyles='solid',cmap=cm.jet_r) a=fig.colorbar(cs,ax=axs[4],orientation='horizontal') ticks = a.ax.get_xticklines() #print getp(a.ax) for tick in ticks: setp(tick,alpha=0) Would be great if someone could tell me how to do the 2 other things ... Many thanks -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- Start uncovering the many advantages of virtual appliances and start using them to simplify application deployment and accelerate your shift to cloud computing http://p.sf.net/sfu/novell-sfdev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] missing label in colorbar
Hi Everyone, I solved the issue using the following code: CS=ax1.pcolormesh(x,y,dolomites,vmin=0, vmax=max(dolomite),cmap=cm.jet_r) fig.colorbar(CS,ticks=[0,max(dolomite)],orientation='horizontal',aspect=40,format='%.1E') ax1.set_title(dolomite [phi]) It's not straight forward to understand, I hope my question will be a good answer for others... Cheers, -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Bad Marshal data when importing matplotlib
ׁHi, Sorry for the late reply. Yes the solution suggested in reply to my bug report was indeed helpful ! Thanks for the help ! Oz On Wed, Aug 4, 2010 at 5:01 PM, Benjamin Root ben.r...@ou.edu wrote: On Wed, Aug 4, 2010 at 12:26 AM, Oz Nahum nahu...@gmail.com wrote: Hi Everyone ! This is urgent, I have to finish some plots by tomorrow, and I totally lost the ability to work with python matplotlib - import pylab from pylab import * all yield the following error: [code]Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/pymodules/python2.6/pylab.py, line 1, in module from matplotlib.pylab import * File /usr/lib/pymodules/python2.6/matplotlib/pylab.py, line 206, in module from matplotlib import mpl # pulls in most modules File /usr/lib/pymodules/python2.6/matplotlib/mpl.py, line 3, in module from matplotlib import axes File /usr/lib/pymodules/python2.6/matplotlib/axes.py, line 17, in module import matplotlib.dates as mdates File /usr/lib/pymodules/python2.6/matplotlib/dates.py, line 87, in module import pytz File /usr/lib/python2.6/dist-packages/pytz/__init__.py, line 32, in module from pkg_resources import resource_stream ValueError: bad marshal data [/code] I am using python-matplotlib on Debian Squeeze. Any help would be appreciated ! Thanks, Oz, I see you have filed a bug with the Debian people and have gotten a response. Did their suggestion help you? http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=591606 Ben Root -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://p.sf.net/sfu/dev2dev-palm___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Bad Marshal data when importing matplotlib
Hi Everyone ! This is urgent, I have to finish some plots by tomorrow, and I totally lost the ability to work with python matplotlib - import pylab from pylab import * all yield the following error: [code]Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/pymodules/python2.6/pylab.py, line 1, in module from matplotlib.pylab import * File /usr/lib/pymodules/python2.6/matplotlib/pylab.py, line 206, in module from matplotlib import mpl # pulls in most modules File /usr/lib/pymodules/python2.6/matplotlib/mpl.py, line 3, in module from matplotlib import axes File /usr/lib/pymodules/python2.6/matplotlib/axes.py, line 17, in module import matplotlib.dates as mdates File /usr/lib/pymodules/python2.6/matplotlib/dates.py, line 87, in module import pytz File /usr/lib/python2.6/dist-packages/pytz/__init__.py, line 32, in module from pkg_resources import resource_stream ValueError: bad marshal data [/code] I am using python-matplotlib on Debian Squeeze. Any help would be appreciated ! Thanks, -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://p.sf.net/sfu/dev2dev-palm___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] which interpolation type is used by contour() ?
Hi Eric, Thanks for your reply. I've already suspected that it's a simple linear interpolation like in matlab. And for better interpolation I should use griddata on a finer grid. That's all clear now ! -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] which interpolation type is used by contour() ?
Hi Everyone, I'd like to know, what is the underline mechanism that connects the points of my gridded data when I use contour(). Can I control this mechanism ? Maybe I missed it in the documentation, but it's not clear to me. Thanks in advance, -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] setting scientific number notation on colorbar
Hi Guys, I'm breaking my head how to use scientific numbering on color bar: I use the following code to plot data from multiple files, would be great if someone could direct me, becuase the numbers I have are 0.0013 et. and what ever I do, the number just go over each other: for i in xrange(len(data)): x,z,som=data[i][x],data[i][z],data[i]['ch2o'] som=som*MwSOM som=som*1000 x=N.unique(x) z=N.unique(z) p_w=N.unique(som) fig = plt.figure(len(data)+1+i) ax1 = fig.add_subplot(111) som=resize(som,(z.size,x.size)) v=N.arange(1.15,1.18,0.002) CS=contourf(x,z,som,cmap=cm.pink_r) cb=colorbar(CS, orientation='horizontal', shrink=1.0,aspect=33) ax1.set_title(SOM +titles[i]) savefig('Fig'+str(i)+'.png') Thanks in advance ! -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] setting scientific number notation on colorbar
Hi, I wanted to be more clear: the numbers on my figure's color bar range from 0 to 1.7, but mpl writes the following numbers: 0., 0.000250,0.50,0.000750, etc. This is totally not somthing I can use, it looks horrible. I'm also attaching the image ... -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace attachment: Fig0.png-- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] setting scientific number notation on colorbar
found a solution after 2 hours ... colorbar(ax=ax1, orientation='horizontal',format='%.3f') now, I need to know how to set up limits for all the images which are exactly the same limits. So far I'm failing with the use of boundaries Would be happy to know -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] setting scientific number notation on colorbar
Hi Thanks for the answer, actually, I always use show and plot, I have no clue how to use the functions you suggested ... I'll look into it. Do you have an idea where I can find a description of the keyword format '%.3f' is nice, but still not scientific format... is this like Fortran? On Mon, May 31, 2010 at 5:41 PM, Benjamin Root ben.r...@ou.edu wrote: Oz, Some plotting functions like pcolor and imshow have keyword args for vmin/vmax where you can explicitly set the min and maximum values for the colorscale. There are some more complicated things you can do with the colormap that are more generic to all plotting functions as well, but I would see if using vmin and vmax does the trick for you. Ben Root On Mon, May 31, 2010 at 7:25 PM, Oz Nahum nahu...@gmail.com wrote: found a solution after 2 hours ... colorbar(ax=ax1, orientation='horizontal',format='%.3f') now, I need to know how to set up limits for all the images which are exactly the same limits. So far I'm failing with the use of boundaries Would be happy to know -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] setting scientific number notation on colorbar
hi andre, thanks for your reply, do you know where I can find more documentation about this ? Thanks, On Mon, May 31, 2010 at 5:55 PM, Andre Walker-Loud walksl...@gmail.comwrote: Hi Thanks for the answer, actually, I always use show and plot, I have no clue how to use the functions you suggested ... I'll look into it. Do you have an idea where I can find a description of the keyword format '%.3f' is nice, but still not scientific format... you can use '%.3e' for scientific format. Cheers, Andre is this like Fortran? On Mon, May 31, 2010 at 5:41 PM, Benjamin Root ben.r...@ou.edu wrote: Oz, Some plotting functions like pcolor and imshow have keyword args for vmin/vmax where you can explicitly set the min and maximum values for the colorscale. There are some more complicated things you can do with the colormap that are more generic to all plotting functions as well, but I would see if using vmin and vmax does the trick for you. Ben Root On Mon, May 31, 2010 at 7:25 PM, Oz Nahum nahu...@gmail.com wrote: found a solution after 2 hours ... colorbar(ax=ax1, orientation='horizontal',format='%.3f') now, I need to know how to set up limits for all the images which are exactly the same limits. So far I'm failing with the use of boundaries Would be happy to know -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] accessing colorbar() list of values
Hi, I open another thread because I think this is not related. I have figured out how to create scientific notation in the color bar. However, by default Python creates really ugly values for printing: 1.165E+00, 1.167E+00... etc. I figure that they are stored somewhere in a list. I could do : cb=colorbar(ax=ax1, orientation='horizontal',format='%.e') and then with: cb.ax.get_xmajorticklabels i get: bound method Axes.get_xmajorticklabels of matplotlib.axes.Axes object at 0x5716210 But do I actually modify this list I have no clue... Would be happy to know if somebody knows -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Plotting multiline graph with large dataset (6 lines, about 30, 000, 000 points total
Hello Krishna, This is really crazy ploting so many data point, after all the human eye can't separate all the data. Try sampling the vector of the data point - to a smaller extent. Here's a quick and dirty solution how to sample every nth element in a vector - there's probably a faster way, with out loops, but this works for now $ python Python 2.5.5 (r255:77872, Feb 1 2010, 19:53:42) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. from nupmy import arange Traceback (most recent call last): File stdin, line 1, in module ImportError: No module named nupmy from numpy import arange a=arange(1,15) a array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) from numpy import zeros a_sampled=zeros(5) a_sampled array([ 0., 0., 0., 0., 0.]) range(0,15,5) [0, 5, 10] range(0,15,3) [0, 3, 6, 9, 12] fileter_indecies=range(0,15,3) for i in range(len(a_sampled)): ... a_sampled[i]=a[fileter_indecies[i]] ... a_sampled array([ 1., 4., 7., 10., 13.]) I hope it helps -- Oz Nahum Graduate Student Zentrum für Angewandte Geologie Universität Tübingen --- Imagine there's no countries it isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace -- SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a logarithmic regression to scattered data ?
but you should be able to adapt the example below to your needs. This example shows how to fit a gaussian to some noisy data. This sure helps, thanks. I don't know if scipy has a logarithmic regression predefined, so my question still stands. I'm still interested in logarithmic regression. If anyone know a good example of the logarithmic regression, i'll be happy to see how it's done. Oz. -- Imagine there's no countries It isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion. Robert Pirsig, Zen and the Art of Motorcycle Maintenance -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] ploting a logarithmic regression to scattered data ?
Hi, I can't find a way to do a logarithmic regression in matplotlib, This can be done relatively easily in spread sheets like gnumeric and excel. Has anyone got a clue how to do it ? Thanks, Oz. -- Imagine there's no countries It isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace --- when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion. Robert Pirsig, Zen and the Art of Motorcycle Maintenance -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] regression coeffiecients
I'm answering to myself on the mailing list just in case it might help some in the future. As, someone pointed out the error is in the assignment operator: I wrote in the code: sum1 =+ (i-mx)*(j-my) which does not add the values but puts them. Instead I should have wrote sum1 += (i-mx)*(j-my) a little difference that does a lot... :-) here is the correct function: def slope(x,y): sum1 = 0 sum2 = 0 mx = mean(x) my = mean(y) for i,j in zip(x,y): sum1 += (i-mx)*(j-my) print sum1 sum2 += (i-mx)**2 slope = sum1/sum2 return slope -- .''`. : :' : We are debian.org. Lower your prices, `. `' surrender your code. `-We will add your hardware and software distinctiveness to our own. Resistance is futile. Imagine there's no countries It isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace You all must read 'The God Delusion' http://en.wikipedia.org/wiki/The_God_Delusion --- when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion. Robert Pirsig, Zen and the Art of Motorcycle Maintenance - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] regression coeffiecients
Hello, I'm having troubles understand something about regression coefficients. If I have two vectors: x = [1.38, 1.98, 3.18, 3.56, 4.9, 6.21, 6.44, 7.47, 8.36, 8.81] y = [8.19, 17.77, 20.12, 14.55, 20.17 ,31.22 ,28.94, 34.79, 40.26, 38.99] and I would like to find out the regression coefficient I can use polyfit: b1, b = polyfit(x,y,1) my first question is can I get from polyfit the corrlation coeficient (I know about corrcoef, just looking for more opotions). The second question is about a fuction I wrote: according to http://en.wikipedia.org/wiki/Regression_analysis#Linear_regression it's pretty easy to write a little python funcion to calculate the regression coefficients. Here is mine: def b1(x,y): sum1 = 0 sum2 = 0 mx = mean(x) my = mean(y) for i,j in zip(x,y): sum1 =+ (i-mx)*(j-my) print sum1 sum2 =+ (i-mx)**2 b1 = sum1/sum2 return b1 both methods yeild two different b1 values. Can anyone please tell me what wrong with my function ? Thanks, Oz. -- .''`. : :' : We are debian.org. Lower your prices, `. `' surrender your code. `-We will add your hardware and software distinctiveness to our own. Resistance is futile. Imagine there's no countries It isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace You all must read 'The God Delusion' http://en.wikipedia.org/wiki/The_God_Delusion --- when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion. Robert Pirsig, Zen and the Art of Motorcycle Maintenance - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] plotting scattered data from array
Hi, Thanks for your reply and appologies for my late response. This indeed does the job. But after playing a little bit with the code, I have discovered a few things: first, I'd rather work with lists not tuples so I could actually change my huge array of points. second the array I described is kind of a pseudo 2D: It has one big row. head = [[0,0,10], [1,0,13], [2,0,11], [3,0,12], [1,2,11]] When I try to use a 3D array, with rows and columns import pylab as pl head = [[[0,0,10], [0,1,13]], [[1,0,11], [1,1,12]], [[2,1,11], [2,2,14]]] x, y, z = zip(*head) xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1) g = pl.griddata(x, y, z, xi, yi) pl.scatter(x, y) pl.contour(xi, yi, g) pl.show() I get this error: Traceback (most recent call last): File asfplot.py, line 9, in module x, y, z = zip(*head) ValueError: need more than 2 values to unpack On Sat, Sep 20, 2008 at 2:19 PM, Goyo [EMAIL PROTECTED] wrote: Try something like this: import pylab as pl head = ((0,0,10), (1,0,13), (2,0,11), (3,0,12), (1,2,11)) x, y, z = zip(*head) xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1) g = pl.griddata(x, y, z, xi, yi) pl.scatter(x, y) pl.contour(xi, yi, g) Level values are automatically chosen in this example but you can provide the number of values or a sequence of them. Note that no extrapolation is done outside convex hull defined by input data. Goyo El sáb, 20-09-2008 a las 11:13 +0200, Oz Nahum escribió: I'm trying again to understand how to plot scattered data from array into contour graph. I looked at http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data and I understand I have to grid my data. However, in most samples the plot is of a function. Let's say I want to plot some geological data, suppose water table head, and I have the following 3D aray x yhead head = ((0,0,10), (1,0,13), (2,0,11), (3,0,12), (1,2,11)) matplotlib has lot's of restrictions about how I can plot and interpolate the data, which causes a lot of confusion in my side... I'll be happy if someone could supply me a clue of how to plot contours of data which comes in arrays or raster format and not an equation. Thanks, Oz - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users -- .''`. : :' : We are debian.org. Lower your prices, `. `' surrender your code. `- We will add your hardware and software distinctiveness to our own. Resistance is futile. Imagine there's no countries It isn't hard to do Nothing to kill or die for And no religion too Imagine all the people Living life in peace You all must read 'The God Delusion' http://en.wikipedia.org/wiki/The_God_Delusion --- when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion. Robert Pirsig, Zen and the Art of Motorcycle Maintenance - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] plotting scattered data from array
I'm trying again to understand how to plot scattered data from array into contour graph. I looked at http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data and I understand I have to grid my data. However, in most samples the plot is of a function. Let's say I want to plot some geological data, suppose water table head, and I have the following 3D aray x yhead head = ((0,0,10), (1,0,13), (2,0,11), (3,0,12), (1,2,11)) matplotlib has lot's of restrictions about how I can plot and interpolate the data, which causes a lot of confusion in my side... I'll be happy if someone could supply me a clue of how to plot contours of data which comes in arrays or raster format and not an equation. Thanks, Oz - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] ploting a contour graph from data files
Hi, I want to draw a contour plot which uses data from files. I know how to import the files, so it's not the main issue. Let's say I want to do a profile which has the following data: distance, depth and some oceanographic data like temp, oxygen and stuff so for simplicity lets say I have: distance = [1,2,3,4,5,6,7,8,9] depth = [1,2,3,4,5,6,7,8,9] temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18] how do I produce a countour plot were distanc is X, Y is depth and the contours are for temp ? many thanks... Oz - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a contour graph from data files
Thanks for the quick answer. So if I have a series of 18 points withe measured distance, and 18 data points with distance, it makes it almost impossible to build the graph ??? I can't type 18^18 points I want the computer to plot the points and extrapulate between them... excuse me the possibly dumb question, I am new to sceintific programming and for matplotlib Oz On Wed, Jul 16, 2008 at 7:51 PM, Eric Firing [EMAIL PROTECTED] wrote: Oz Nahum wrote: Hi, I want to draw a contour plot which uses data from files. I know how to import the files, so it's not the main issue. Let's say I want to do a profile which has the following data: distance, depth and some oceanographic data like temp, oxygen and stuff so for simplicity lets say I have: distance = [1,2,3,4,5,6,7,8,9] depth = [1,2,3,4,5,6,7,8,9] temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18] Too simple. If your grid has 9 points in distance and 9 in depth, then you need 81 values of temperature (9 profiles of 9 depths each). Suppose you have 10 profiles of 8 points each. Then your temperature array should have shape (8,10). Your distance and depth arrays can either have the same shape as temperature, or both can be 1-D, in which case distance.shape = (10,) and depth.shape = (8,). Either way, you then use (assuming a current release of mpl) from matplotlib import pyplot as plt plt.contour(distance, depth, temperature) plt.gca().invert_yaxis() # so depth increases down the y-axis plt.show() Note that the shape of your temperature array is the transpose of what one might expect. This is for matlab compatibility, and goes with the idea of looking at an array as it is printed, with the column dimension (second index) increasing across the page. See the contour_demo.py and contourf_demo.py in the mpl examples. Eric how do I produce a countour plot were distanc is X, Y is depth and the contours are for temp ? many thanks... Oz - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a contour graph from data files
Ok, I played with it a little bit. Here is what I know: importing the data is not a big issue, I aready wrote a tutorial about it here: http://www.tabula0rasa.org/?p=21 here is a sample code I wrote. from matplotlib import pyplot as plt from pylab import * temperature=[ [1,3,4], [2,4,5], [6,3,2] ] distance = (100,200,300) depth = (10,30,50) plt.colorbar() plt.contourf(distance,depth,temperature) plt.gca().invert_yaxis() plt.show() Can I plot the dots as different series on top of the contours ? many many 10x. Oz On Wed, Jul 16, 2008 at 8:58 PM, Eric Firing [EMAIL PROTECTED] wrote: Oz Nahum wrote: Thanks for the quick answer. So if I have a series of 18 points withe measured distance, and 18 data points with distance, it makes it almost impossible to build the graph ??? I can't type 18^18 points I want the computer to plot the points and extrapulate between them... I'm puzzled. You said you knew how to read in your data from files, so there should be no question of having to type too many numbers. Eric excuse me the possibly dumb question, I am new to sceintific programming and for matplotlib Oz On Wed, Jul 16, 2008 at 7:51 PM, Eric Firing [EMAIL PROTECTED] mailto: [EMAIL PROTECTED] wrote: Oz Nahum wrote: Hi, I want to draw a contour plot which uses data from files. I know how to import the files, so it's not the main issue. Let's say I want to do a profile which has the following data: distance, depth and some oceanographic data like temp, oxygen and stuff so for simplicity lets say I have: distance = [1,2,3,4,5,6,7,8,9] depth = [1,2,3,4,5,6,7,8,9] temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18] Too simple. If your grid has 9 points in distance and 9 in depth, then you need 81 values of temperature (9 profiles of 9 depths each). Suppose you have 10 profiles of 8 points each. Then your temperature array should have shape (8,10). Your distance and depth arrays can either have the same shape as temperature, or both can be 1-D, in which case distance.shape = (10,) and depth.shape = (8,). Either way, you then use (assuming a current release of mpl) from matplotlib import pyplot as plt plt.contour(distance, depth, temperature) plt.gca().invert_yaxis() # so depth increases down the y-axis plt.show() Note that the shape of your temperature array is the transpose of what one might expect. This is for matlab compatibility, and goes with the idea of looking at an array as it is printed, with the column dimension (second index) increasing across the page. See the contour_demo.py and contourf_demo.py in the mpl examples. Eric how do I produce a countour plot were distanc is X, Y is depth and the contours are for temp ? many thanks... Oz - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/ ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a contour graph from data files
Hi Eric, really thanks for your help so far. I am doing a quick short course, and I'll do the examples later. I've fixed the code, here it is: from matplotlib import pyplot as plt temperature=[ [10,8,6], [9,7,5], [8,7,4] ] distance = (100,200,300) depth = (100,300,700) x = distance y = depth z = temperature m = plt.contourf(x,y,z) plt.gca().invert_yaxis() plt.colorbar(m) plt.show(m) the trouble now that the contours seems wrong... and my question still stands. I'd like to do the plot as said: contours + series, can you show me where I'm wrong ? thanks, Oz On Wed, Jul 16, 2008 at 9:37 PM, Eric Firing [EMAIL PROTECTED] wrote: Oz Nahum wrote: Ok, I played with it a little bit. Here is what I know: importing the data is not a big issue, I aready wrote a tutorial about it here: http://www.tabula0rasa.org/?p=21 here is a sample code I wrote. from matplotlib import pyplot as plt from pylab import * temperature=[ [1,3,4], [2,4,5], [6,3,2] ] distance = (100,200,300) depth = (10,30,50) plt.colorbar() plt.contourf(distance,depth,temperature) plt.gca().invert_yaxis() plt.show() Can I plot the dots as different series on top of the contours ? First you have to make your basic example work; what you posted above does not. 1) For an example like this, use a different number of points in the x and y directions, to make it clear how the arrays are oriented. 2) The colorbar command must *follow* the contourf command. 3) Make your test temperature profiles more reasonable, i.e. temperature decreasing with depth, so you can see whether your plot is doing the right thing. 4) Omit the from pylab import * 5) Once you start doing real work, you will need numpy. The suggested import syntax is import numpy as np. 6) Study the examples that come with mpl. Eric - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a contour graph from data files
Here is why the contours are wrong: they are ploted verticaly, while I think, it is more common to draw temp. contours in oceanography when the are horizontal. Also, one more thing, I can't find how to expand the borders of the plot, say from 350 to 400 (same for depth) I tried usig xlim and ylim(0,900) but no result. Here is my code now, I can't really get it, ha ? another issue is that I've added anoter temp. series but it won't show it. I still see 3 rows. from matplotlib import pyplot as plt from pylab import * temperature=[ [9,8,6], [9,7,6], [9,7,6], [9,6,6] ] distance = (0,200,350) depth = (100,250,250,700) x = distance y = depth z = temperature #m = plt.contourf(x,y,z) m = plt.contour(x,y,z) ylabel('Depth') xlabel('Distance') ylim(0,1200) #plt.xlim(0,500) plt.gca().invert_yaxis() #plt.colorbar(m) import numpy as np X, Y = np.meshgrid(x,y) #plt.hold(True) # probably not necessary plt.plot(X,Y, 'o') plt.show(m) On Wed, Jul 16, 2008 at 10:28 PM, Eric Firing [EMAIL PROTECTED] wrote: Oz Nahum wrote: Hi Eric, really thanks for your help so far. I am doing a quick short course, and I'll do the examples later. I've fixed the code, here it is: from matplotlib import pyplot as plt temperature=[ [10,8,6], [9,7,5], [8,7,4] ] distance = (100,200,300) depth = (100,300,700) x = distance y = depth z = temperature m = plt.contourf(x,y,z) plt.gca().invert_yaxis() plt.colorbar(m) plt.show(m) the trouble now that the contours seems wrong... and my question still stands. I'd like to do the plot as said: contours + series, can you show me where I'm wrong ? The plot looks right to me--I see 4 degrees in the lower RH corner, 300 distance units and 700 depth units. Why do you say the contours seem wrong? As for plotting the series, what do you mean? Put circles on the data points? Then include something like this, after the call to contourf: import numpy as np X, Y = np.meshgrid(x,y) plt.hold(True) # probably not necessary plt.plot(X,Y, 'o') Eric thanks, Oz On Wed, Jul 16, 2008 at 9:37 PM, Eric Firing [EMAIL PROTECTED] mailto: [EMAIL PROTECTED] wrote: Oz Nahum wrote: Ok, I played with it a little bit. Here is what I know: importing the data is not a big issue, I aready wrote a tutorial about it here: http://www.tabula0rasa.org/?p=21 here is a sample code I wrote. from matplotlib import pyplot as plt from pylab import * temperature=[ [1,3,4], [2,4,5], [6,3,2] ] distance = (100,200,300) depth = (10,30,50) plt.colorbar() plt.contourf(distance,depth,temperature) plt.gca().invert_yaxis() plt.show() Can I plot the dots as different series on top of the contours ? First you have to make your basic example work; what you posted above does not. 1) For an example like this, use a different number of points in the x and y directions, to make it clear how the arrays are oriented. 2) The colorbar command must *follow* the contourf command. 3) Make your test temperature profiles more reasonable, i.e. temperature decreasing with depth, so you can see whether your plot is doing the right thing. 4) Omit the from pylab import * 5) Once you start doing real work, you will need numpy. The suggested import syntax is import numpy as np. 6) Study the examples that come with mpl. Eric - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a contour graph from data files
You can transpose your inputs. For numpy arrays: x = x.transpose() i wrote: for np arrays: x = x.transpose() but I still get a syntax error. Also, one more thing, I can't find how to expand the borders of the plot, say from 350 to 400 (same for depth) I tried usig xlim and ylim(0,900) but no result. Subsequent calls to plot will call the autoscaler, so either you need to set the xlim *after* all the plotting commands or turn off autoscaling entirely by passing the autoscale_on=False property to the axes, eg plt.gca().set_autoscale_on(False) That does for the one of the problems. And I still haven't manage to plot the 4th series. still many thanks... hope I can figure this out... - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] ploting a contour graph from data files
Dear Mike, I really laughed. Many thanks. It's almost to late for me to really understand the code now. But some how you managed to throw in some stuff that can help: you've made what I've wanted except for the dolphin. I am sorry about the exagerating, but everybody here keep talking about this young dolphin that keeps swimming around the reef here (I am in Eilat, northren tip of Gulf of Aqaba). Anyways, many thanks for you people trying to help. Oz. On Thu, Jul 17, 2008 at 12:12 AM, Michael Droettboom [EMAIL PROTECTED] wrote: Oz Nahum wrote: I am mostly frustrated with documentation writers who write very nice tutorials describing how to plot completely unusfull graphs of spheres inside loops and a dolphin swimming in the middle. I'm sorry. I just couldn't resist writing a tutorial example for this. Please take it in the spirit of fun it was intended. Mike -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA import matplotlib.pyplot as plt from matplotlib.patches import Circle, PathPatch from matplotlib.path import Path from matplotlib.transforms import Affine2D import numpy as np r = np.random.rand(50) t = np.random.rand(50) * np.pi * 2.0 x = r * np.cos(t) y = r * np.sin(t) fig = plt.figure(figsize=(6,6)) ax = plt.subplot(111) circle = Circle((0, 0), 1, facecolor=(0,0,0.8), edgecolor=(0,0.8,0.8), linewidth=3, alpha=0.5) ax.add_patch(circle) plt.plot(x, y, 'o', color=(0.9, 0.9, 1.0), alpha=0.8) # Dolphin from OpenClipart library by Andy Fitzsimon # cc:License rdf:about=http://web.resource.org/cc/PublicDomain; # cc:permits rdf:resource= http://web.resource.org/cc/Reproduction/ # cc:permits rdf:resource= http://web.resource.org/cc/Distribution/ # cc:permits rdf:resource= http://web.resource.org/cc/DerivativeWorks/ # /cc:License dolphin = M -0.59739425,160.18173 C -0.62740401,160.18885 -0.57867129,160.11183 -0.57867129,160.11183 C -0.57867129,160.11183 -0.5438361,159.89315 -0.39514638,159.81496 C -0.24645668,159.73678 -0.18316813,159.71981 -0.18316813,159.71981 C -0.18316813,159.71981 -0.10322971,159.58124 -0.057804323,159.58725 C -0.029723983,159.58913 -0.061841603,159.60356 -0.071265813,159.62815 C -0.080250183,159.65325 -0.082918513,159.70554 -0.061841203,159.71248 C -0.040763903,159.7194 -0.0066711426,159.71091 0.077336307,159.73612 C 0.16879567,159.76377 0.28380306,159.86448 0.31516668,159.91533 C 0.3465303,159.96618 0.5011127,160.1771 0.5011127,160.1771 C 0.63668998,160.19238 0.67763022,160.31259 0.66556395,160.32668 C 0.65339985,160.34212 0.66350443,160.33642 0.64907098,160.33088 C 0.63463742,160.32533 0.61309688,160.297 0.5789627,160.29339 C 0.54348657,160.28968 0.52329693,160.27674 0.50728856,160.27737 C 0.49060916,160.27795 0.48965803,160.31565 0.46114204,160.33673 C 0.43329696,160.35786 0.4570711,160.39871 0.43309565,160.40685 C 0.4105108,160.41442 0.39416631,160.33027 0.3954995,160.2935 C 0.39683269,160.25672 0.43807996,160.21522 0.44567915,160.19734 C 0.45327833,160.17946 0.27946869,159.9424 -0.061852613,159.99845 C -0.083965233,160.0427 -0.26176109,160.06683 -0.26176109,160.06683 C -0.30127962,160.07028 -0.21167141,160.09731 -0.24649368,160.1011 C -0.32642366,160.11569 -0.34521187,160.06895 -0.40622293,160.0819 C -0.467234,160.09485 -0.56738444,160.17461 -0.59739425,160.18173 vertices = [] codes = [] parts = dolphin.split() i = 0 code_map = { 'M': (Path.MOVETO, 1), 'C': (Path.CURVE4, 3), 'L': (Path.LINETO, 1) } while i len(parts): code = parts[i] path_code, npoints = code_map[code] codes.extend([path_code] * npoints) vertices.extend([[float(x) for x in y.split(',')] for y in parts[i+1:i+npoints+1]]) i += npoints + 1 vertices = np.array(vertices, np.float) vertices[:,1] -= 160 dolphin_path = Path(vertices, codes) dolphin_patch = PathPatch(dolphin_path, facecolor=(0.6, 0.6, 0.6), edgecolor=(0.0, 0.0, 0.0)) ax.add_patch(dolphin_patch) vertices = Affine2D().rotate_deg(60).transform(vertices) dolphin_path2 = Path(vertices, codes) dolphin_patch2 = PathPatch(dolphin_path2, facecolor=(0.5, 0.5, 0.5), edgecolor=(0.0, 0.0, 0.0)) ax.add_patch(dolphin_patch2) plt.show() - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] ocean profile
So, after mailing all the previous mails, I've thought maybe I'm not asking the right question. What I want to do plot is a cross section, and there is no easy way to extrapulate between points. Not in excell and not in matlab. here is a simplification: distance _ | | x x | x x x | | yy yy y y | | z | z z z z | | suppose the letters represent the temps: 29, 26, 23 deg. cel. and the unmarked y axis is depth. Now I want to draw contours between the x's y's and z's. This will allow me to create very quickly lots' of graph of temp. prfiles of the gulf. Many thanks, again. Oz - This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100url=/___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] Creating an oceanographic profile with matplotlib
Thank you very much ! That did it for me. If I get it right ax=twiny or ax=gca() defines the plot type ? On Fri, Jun 13, 2008 at 9:35 PM, Abhinav Verma [EMAIL PROTECTED] wrote: or more appropriately you might need this from pylab import * setp(gca(), 'xticklabels', []) subplot(111) ax=twiny() y = [1, 2, 3, 4] x = [5, 4, 2, 2] plot(x, y, 'ro-') ylim(5,0) xlim(1,6) ax.xaxis.tick_top() xlabel('Y') ylabel('X') show() On Fri, Jun 13, 2008 at 10:24 AM, Oz Nahum [EMAIL PROTECTED] wrote: Hi all, I am trying to plot an oceanographic profile using some ocean data I have. The thing is that in oceanograhy it is common to display graphs where the independent variable (x) is depth, and some other data (i.e salinity or temperature) is plotted against it. The graph is supposed to look like this for example: y ___ |* | * | * * * |* | * | * x | * | * |* | * |* | * |* | * | * | * so far I have managed to plot the graph with invert x axis, but I don't know how to change the default graph option of intercept of axes in the bottom left corner. So I hope I made my question clear: how can I plot a graph with intecept of axes in the upper left corner ? Thanks, Oz Nahum, Department of Oceanography, Hebrew University, Jerusalem - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] Creating an oceanographic profile with matplotlib
Hi all, I am trying to plot an oceanographic profile using some ocean data I have. The thing is that in oceanograhy it is common to display graphs where the independent variable (x) is depth, and some other data (i.e salinity or temperature) is plotted against it. The graph is supposed to look like this for example: y ___ |* | * | * * * |* | * | * x | * | * |* | * |* | * |* | * | * | * so far I have managed to plot the graph with invert x axis, but I don't know how to change the default graph option of intercept of axes in the bottom left corner. So I hope I made my question clear: how can I plot a graph with intecept of axes in the upper left corner ? Thanks, Oz Nahum, Department of Oceanography, Hebrew University, Jerusalem - Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users