Re: [Tutor] Plotting with python
On 31 October 2015 at 00:00, Terry Carrollwrote: > If you were going to get started doing some simple plotting with Python 2.7 > (in my case, I'm simply plotting temperature against time-of-day) what would > you use? > > - matplotlib [1] > - gnuplot [2] > - something else entirely? I'd use matplotlib. > Assume no substantial familiarity with the underlying plotting software, let > alone the Python bindings. > > The only thing I can think of that might be special is to specify the > upper/lower bounds of the plot; for example, in my case, I know the > temperatures vary between somewhere around 70-78 degrees F., so I'd want the > Y-axis to go, say 60-90, not arbitrarily start at zero; but I suspect this > is a pretty standard thing in almost any plotting package. This is straightforward in most plotting packages. Here's a simple example of doing it in matplotlib: #!/usr/bin/env python3 import matplotlib.pyplot as plt times = [0, 1, 2, 3, 4, 5] # hours temperatures = [68, 70, 75, 73, 72, 71] # Fahrenheit fig = plt.figure(figsize=(5, 4)) ax = fig.add_axes([0.15, 0.15, 0.70, 0.70]) ax.plot(times, temperatures) ax.set_xlabel('Time (hours)') ax.set_ylabel(r'Temp ($^{\circ}\mathrm{F}$)') ax.set_title('Temperature vs time') plt.show() -- Oscar ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Plotting with python
I'd use matplotlib, unless the ultimate goal is to render onto a webpage. Then I would use bokeh. http://bokeh.pydata.org/en/latest/ Laura ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Plotting with python
If you were going to get started doing some simple plotting with Python 2.7 (in my case, I'm simply plotting temperature against time-of-day) what would you use? - matplotlib [1] - gnuplot [2] - something else entirely? Assume no substantial familiarity with the underlying plotting software, let alone the Python bindings. The only thing I can think of that might be special is to specify the upper/lower bounds of the plot; for example, in my case, I know the temperatures vary between somewhere around 70-78 degrees F., so I'd want the Y-axis to go, say 60-90, not arbitrarily start at zero; but I suspect this is a pretty standard thing in almost any plotting package. [1] http://matplotlib.org/api/pyplot_api.html [2] http://gnuplot-py.sourceforge.net/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Plotting with python
On 31/10/2015 00:00, Terry Carroll wrote: If you were going to get started doing some simple plotting with Python 2.7 (in my case, I'm simply plotting temperature against time-of-day) what would you use? - matplotlib [1] - gnuplot [2] - something else entirely? Assume no substantial familiarity with the underlying plotting software, let alone the Python bindings. The only thing I can think of that might be special is to specify the upper/lower bounds of the plot; for example, in my case, I know the temperatures vary between somewhere around 70-78 degrees F., so I'd want the Y-axis to go, say 60-90, not arbitrarily start at zero; but I suspect this is a pretty standard thing in almost any plotting package. [1] http://matplotlib.org/api/pyplot_api.html [2] http://gnuplot-py.sourceforge.net/ matplotlib, I gave up gnuplot in favour of it maybe 15 years ago and have never looked back. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Plotting with python
>> If you were going to get started doing some simple plotting with Python >> 2.7 (in my case, I'm simply plotting temperature against time-of-day) >> what would you use? >> >> - matplotlib [1] >> - gnuplot [2] >> - something else entirely? >> >> Assume no substantial familiarity with the underlying plotting software, >> let alone the Python bindings. >> >> The only thing I can think of that might be special is to specify the >> upper/lower bounds of the plot; for example, in my case, I know the >> temperatures vary between somewhere around 70-78 degrees F., so I'd want >> the Y-axis to go, say 60-90, not arbitrarily start at zero; but I >> suspect this is a pretty standard thing in almost any plotting package. >> >> [1] http://matplotlib.org/api/pyplot_api.html >> [2] http://gnuplot-py.sourceforge.net/ > > matplotlib, I gave up gnuplot in favour of it maybe 15 years ago and have > never > looked back. I think my transition was later and I'm modestly bilingual with these tools. However, in principle, I agree with Mark--IF you are primarily using Python as your tool for massaging and exploring data. If you are, then I might add one more suggestion. There's a project called 'IPython' [0] which has built a very nicely extended and richer interactive interface to the Python interpreter. You can use IPython as a replacement for the Python interactive shell. I have for years, and it's wonderful (even though, I also use the interactive shell that ships with the system supplied Python I use). Why am I talking about IPython? Aside from other benefits, the IPython Notebook [1] is directly useful to those who are also matplotlib users, because it allows you to record an entire analysis session, display graphics inline (see macro "%matplotlib inline") and then later, share the data explorations in a web browser. N.B. I have not found any running, public IPython Notebooks. This doesn't surprise me, because of the security risks of allowing just anybody access to a Python instance is like letting strangers into your kitchen. They might eat all of your food, or try to crack that safe behind the portrait in the dining room. http://calebmadrigal.com/graph-ipython-notebook/ So, if I were in your shoes, starting today, I'd install IPython and matplotlib and then fire up the IPython Notebook on my local machine, type '%matplotlib inline' and start trying to display my data. One nice feature of matplotlib is that it autoscales by default. So, if all of your values (temperature) are within the range you want to display, you don't need to mess with the axes. See their tutorial: http://matplotlib.org/users/pyplot_tutorial.html Good luck and enjoy! -Martin [0] http://ipython.org/ [1] http://ipython.org/notebook.html -- Martin A. Brown http://linux-ip.net/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
The output of the print len(Conc[0]), len(z) is 100 3600. Now I changed Conc[0] to Conc[1], and the output is: 100 100 But still I need to see from Concentration from 0. On Thu, Dec 1, 2011 at 5:26 AM, Asokan Pichai paso...@talentsprint.com wrote: On Thu, Dec 1, 2011 at 2:38 AM, stm atoc stm.at...@googlemail.com wrote: Hi there, I have a question regarding plotting with Python. I have the following python script: [SNIPPED] plot(Conc[0],z) [SNIPPED] ---So, What would you suggest? What is the output of print len(Conc[0]), len(z) You may insert that line above the plot and see Asokan Pichai ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
[Please don't top-post. Put your answers below the text you cite.] On 2011-12-01 09:01, stm atoc wrote: The output of the print len(Conc[0]), len(z) is 100 3600. Now I changed Conc[0] to Conc[1], and the output is: 100 100 So, you've changed the line print len(Conc[0]), len(z) to print len(Conc[1]), len(z) and the only thing that changed in the output is the length of z which is calculated independently of Conc in your script? This would be very strange. Does your script run if you use Conc[1] (or some other indexes) instead of Conc[0] when you call the plot-function? If yes, it's very likely that you have the wrong data in Conc[0]. But that's impossible to tell without your data file (ourtest_out.list). Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
[Still top-posting :-( ] On 2011-12-01 11:13, stm atoc wrote: Well, I did also change the line in the python script to this: plot(Conc[0],z,'r-',label='initial') plot(Conc[1],z,'b-',label='after 20s') to see both Conc[0] and [1]. And did it work? I will send the output data attaches to this email (ourtest_out.list). I wonder if this way is fine. I'm not sure about the policy regarding attachements on this list but I think it would have been better to provide a link than attach it. Anyways, I've reduced your original script, did a test run and it works as expected (at least it shows a plot): import numpy import matplotlib.pyplot as pyplot with open(ourtest_out.list, r) as f: z = numpy.array([float(v) for v in f.readline().split()[1:]]) a = numpy.loadtxt(ourtest_out.list, skiprows=3) N = 100 Conc = a[1:, N+1:] print len(Conc[0]) == len(z) pyplot.figure() pyplot.plot(Conc[0], z) pyplot.show() Do you still get an error? Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
For previous script that I have written, I had trouble having one plot for all data at the same time and I could see two line for Conc[0] and Conc[1] separately. Now, even I modified Conc = a[1:, N+1:] to Conc = a[0:, N+1:], still one plot is created...which is pretty good and no error! Thank you so much, Sue On Thu, Dec 1, 2011 at 12:39 PM, Andreas Perstinger andreas.perstin...@gmx.net wrote: [Still top-posting :-( ] On 2011-12-01 11:13, stm atoc wrote: Well, I did also change the line in the python script to this: plot(Conc[0],z,'r-',label='initial') plot(Conc[1],z,'b-',label='after 20s') to see both Conc[0] and [1]. And did it work? I will send the output data attaches to this email (ourtest_out.list). I wonder if this way is fine. I'm not sure about the policy regarding attachements on this list but I think it would have been better to provide a link than attach it. Anyways, I've reduced your original script, did a test run and it works as expected (at least it shows a plot): import numpy import matplotlib.pyplot as pyplot with open(ourtest_out.list, r) as f: z = numpy.array([float(v) for v in f.readline().split()[1:]]) a = numpy.loadtxt(ourtest_out.list, skiprows=3) N = 100 Conc = a[1:, N+1:] print len(Conc[0]) == len(z) pyplot.figure() pyplot.plot(Conc[0], z) pyplot.show() Do you still get an error? Bye, Andreas ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] plotting in python
Hi there, I have a question regarding plotting with Python. I have the following python script: # coding: utf-8 from pylab import * import numpy filename='ourtest_out.list' fh=open(filename) line=fh.readline() fh.close z=array([ float(val) for val in line.split()[1:] ]) a = numpy.loadtxt(filename,skiprows=3) N=100 t = a[:,0] nu = a[0:,1:N+1] #Conc = a[1:,N+1:] Conc = a[1:,N+1:] levels=arange(-10,1) levels=levels[-3]-levels t=t/360. figure() plot(Conc[0],z) xlabel('C') ylabel('z') #show() savefig('Conc.png') close() #nu figure() lw = 2.0 #linewidth dpi = 96 levels=arange(-10,1) levels=levels[-3]-levels plot(nu[0],z) xlabel('nu') ylabel('z') savefig('nu.png') close() However, once I run the program (run.py) I have error like this: --- ValueErrorTraceback (most recent call last) /Users/…./run.py in module() 24 25 figure() --- 26 plot(Conc[0],z) 27 28 xlabel('C') /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs) 2284 ax.hold(hold) 2285 try: - 2286 ret = ax.plot(*args, **kwargs) 2287 draw_if_interactive() 2288 finally: /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in plot(self, *args, **kwargs) 3781 lines = [] 3782 - 3783 for line in self._get_lines(*args, **kwargs): 3784 self.add_line(line) 3785 lines.append(line) /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in _grab_next_args(self, *args, **kwargs) 315 return 316 if len(remaining) = 3: -- 317 for seg in self._plot_args(remaining, kwargs): 318 yield seg 319 return /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in _plot_args(self, tup, kwargs) 292 x = np.arange(y.shape[0], dtype=float) 293 -- 294 x, y = self._xy_from_xy(x, y) 295 296 if self.command == 'plot': /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in _xy_from_xy(self, x, y) 232 y = np.atleast_1d(y) 233 if x.shape[0] != y.shape[0]: -- 234 raise ValueError(x and y must have same first dimension) 235 if x.ndim 2 or y.ndim 2: 236 raise ValueError(x and y can be no greater than 2-D) ValueError: x and y must have same first dimension ---So, What would you suggest? Thanks in advance, Sue ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
On Wed, Nov 30, 2011 at 3:08 PM, stm atoc stm.at...@googlemail.com wrote: Hi there, I have a question regarding plotting with Python. snip ValueError: x and y must have same first dimension It looks like something is wrong with the data that you're trying to plot. Specifically, the data that you're trying to plot has the wrong dimensions (like it says). An example: # 2d space: x = [(1, 1), (2, 2), (3,3)] y = [(1,1,1), (2,2,2), (3,3,3)] x is a series of points in 2 dimensions, and y is a series in 3. If your data really is supposed to look like that then you'll need to pad or trim the data so you've got the correct dimensions. HTH, Wayne ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
On 11/30/2011 1:08 PM stm atoc said... Hi there, I have a question regarding plotting with Python. I have the following python script: # coding: utf-8 from pylab import * import numpy filename='ourtest_out.list' fh=open(filename) line=fh.readline() fh.close z=array([ float(val) for val in line.split()[1:] ]) a = numpy.loadtxt(filename,skiprows=3) N=100 t = a[:,0] nu = a[0:,1:N+1] #Conc = a[1:,N+1:] Conc = a[1:,N+1:] levels=arange(-10,1) levels=levels[-3]-levels t=t/360. figure() plot(Conc[0],z) xlabel('C') ylabel('z') #show() savefig('Conc.png') close() #nu figure() lw = 2.0 #linewidth dpi = 96 levels=arange(-10,1) levels=levels[-3]-levels plot(nu[0],z) xlabel('nu') ylabel('z') savefig('nu.png') close() However, once I run the program (run.py) I have error like this: --- ValueErrorTraceback (most recent call last) /Users/…./run.py inmodule() 24 25 figure() --- 26 plot(Conc[0],z) 27 28 xlabel('C') /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs) 2284 ax.hold(hold) 2285 try: - 2286 ret = ax.plot(*args, **kwargs) 2287 draw_if_interactive() 2288 finally: /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in plot(self, *args, **kwargs) 3781 lines = [] 3782 - 3783 for line in self._get_lines(*args, **kwargs): 3784 self.add_line(line) 3785 lines.append(line) /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in _grab_next_args(self, *args, **kwargs) 315 return 316 if len(remaining)= 3: -- 317 for seg in self._plot_args(remaining, kwargs): 318 yield seg 319 return /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in _plot_args(self, tup, kwargs) 292 x = np.arange(y.shape[0], dtype=float) 293 -- 294 x, y = self._xy_from_xy(x, y) 295 296 if self.command == 'plot': /Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/matplotlib/axes.py in _xy_from_xy(self, x, y) 232 y = np.atleast_1d(y) 233 if x.shape[0] != y.shape[0]: -- 234 raise ValueError(x and y must have same first dimension) 235 if x.ndim 2 or y.ndim 2: 236 raise ValueError(x and y can be no greater than 2-D) ValueError: x and y must have same first dimension ---So, What would you suggest? Looking over the traceback and code, it would appear the error is saying that there is an inconsistency with the arguments expected vs the arguments passed, which appears in this case to relate to ... plot(Conc[0],z) ... which derives its parameters from the two lines ... z=array([ float(val) for val in line.split()[1:] ]) ... and ... a = numpy.loadtxt(filename,skiprows=3) So, I'd conclude that I'd need a better understanding of how to use the functions plot, array and numpy.loadtext. Neither plot nor array are python builtins nor defined within your script, so they're likely brought in from ... from pylab import * ... which is generally not something you want to do except when first starting to experiment and learn a new module, and then I'd keep things to the interactive interpreter for testing and discovery. This form of import is generally thought of as polluting the namespace and may allow library specific names to mask python builtins. For example. suppose a module 'xyz' contains a special 'print' function. Executing 'from xyz import *' would shadow the python builtin print function essentially making it inaccessible. It's possible (although unlikely in the case of pylab specifically) that any python builtins that are used in your script have been replaced with pylab versions. A better technique is to simply import pylab and refer to its functions as pylab.xyz so that no ambiguity is possible. So, read up on pylab, find their support list [1], and follow up there. We focus mainly on getting you far enough along with python basics and generally leave specific library support to the library authors and support groups. HTH Emile [1] start at http://www.scipy.org/Mailing_Lists ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting in python
On Thu, Dec 1, 2011 at 2:38 AM, stm atoc stm.at...@googlemail.com wrote: Hi there, I have a question regarding plotting with Python. I have the following python script: [SNIPPED] plot(Conc[0],z) [SNIPPED] ---So, What would you suggest? What is the output of print len(Conc[0]), len(z) You may insert that line above the plot and see Asokan Pichai ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] plotting with python
Friends, I am not sure if this forum is appropriate to ask question about a particular package. After getting suggestions from some of you for python based plotting, I have just started with matplotlib. I am bit confused with the relation between matplotlib and pylab. In the matplotlib homepage, example plots are shown with both * matplotlib.pyplot* and* pylab*. Inaddition within matplotlib, there is a module called *matplotlib.pylab* i) matplotlib and pylab - both are same or different modules ?. Is there any advantage of using one over the other ? ii) Is it like i can plot the graphs with both matplotlib and pylab ? iii) can some kindly show me an example of ploting multy Y axes plot, ie NXY. Thanks in advance, Bala ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting with python
On Fri, Mar 27, 2009 at 7:46 AM, Bala subramanian bala.biophys...@gmail.com wrote: Friends, I am not sure if this forum is appropriate to ask question about a particular package. After getting suggestions from some of you for python based plotting, I have just started with matplotlib. I am bit confused with the relation between matplotlib and pylab. In the matplotlib homepage, example plots are shown with both matplotlib.pyplot and pylab. Inaddition within matplotlib, there is a module called matplotlib.pylab i) matplotlib and pylab - both are same or different modules ?. Is there any advantage of using one over the other ? ii) Is it like i can plot the graphs with both matplotlib and pylab ? IIUC, pylab is part of matplotlib. It provides a simplified, functional (not object-oriented) interface to matplotlib. Using matplotlib directly gives you more control over the result. iii) can some kindly show me an example of ploting multy Y axes plot, ie NXY. Take a look at the gallery for something similar to what you want. Clicking on a gallery image will show you a larger image and the code that created it. http://matplotlib.sourceforge.net/gallery.html Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] plotting with python
matplotlib and pylab are two APIs to the same library. Using matplotlib is a more object-oriented, pythonic API. pylab is modeled after the Matlab plotting functions to make it easier for those coming from that environment. There's a matplotlib mailing list and you can often figure out what you need from perusing the examples and the thumbnail gallery. In your case, I think http://matplotlib.sourceforge.net/examples/api/two_scales.html is what you want. On Fri, Mar 27, 2009 at 7:46 AM, Bala subramanian bala.biophys...@gmail.com wrote: Friends, I am not sure if this forum is appropriate to ask question about a particular package. After getting suggestions from some of you for python based plotting, I have just started with matplotlib. I am bit confused with the relation between matplotlib and pylab. In the matplotlib homepage, example plots are shown with both matplotlib.pyplot and pylab. Inaddition within matplotlib, there is a module called matplotlib.pylab i) matplotlib and pylab - both are same or different modules ?. Is there any advantage of using one over the other ? ii) Is it like i can plot the graphs with both matplotlib and pylab ? iii) can some kindly show me an example of ploting multy Y axes plot, ie NXY. Thanks in advance, Bala ___ Tutor maillist - tu...@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor