Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76651
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-08-20 03:02 -0700 |
| References | (6 earlier) <ce4ee9aa-1ea1-45a3-83ff-e4ed017b4c5f@googlegroups.com> <5a0df87b-6271-48c5-93ec-39949ab7c192@googlegroups.com> <53f295e2$0$29970$c3e8da3$5496439d@news.astraweb.com> <6bc22f4f-1041-4ad4-9a8f-b0b6ec4bd009@googlegroups.com> <87iolo2n0z.fsf@pascolo.net> |
| Message-ID | <408a7442-e9e0-4e78-b045-f0ea22284e6a@googlegroups.com> (permalink) |
| Subject | Re: Matplotlib Contour Plots |
| From | Jamie Mitchell <jamiemitchell1604@gmail.com> |
On Tuesday, August 19, 2014 10:21:48 PM UTC+1, pec...@pascolo.net wrote:
> Jamie Mitchell <jamiemitchell1604@gmail.com> writes:
>
>
>
> > You were right Christian I wanted a shape (2,150).
>
> >
>
> > Thank you Rustom and Steven your suggestion has worked.
>
> >
>
> > Unfortunately the data doesn't plot as I imagined.
>
> >
>
> > What I would like is:
>
> >
>
> > X-axis - hs_con_sw
>
> > Y-axis - te_con_sw
>
> > Z-axis - Frequency
>
> >
>
> > What I would like is for the Z-axis to contour the frequency or
>
> > amount of times that the X-axis data and Y-axis data meet at a
>
> > particular point or bin.
>
> >
>
> > Does anyone know what function or graph could best show this?
>
>
>
> in my understanding, you have 3 arrays of data that describe 3D data
>
> points, and you want to draw a 2D contour plot...
>
>
>
> in this case you have to interpolate the z-values on a regular grid,
>
> that's very easy if you already know what to do ;-)
>
>
>
> here I assume that data is in a .csv file
>
>
>
> % cat a.csv
>
> 0 ≤ x ≤ 10, 0 ≤ y ≤ 10, z = cos(sqrt((x-5)**2_(y-5)**2))
>
> 1.922065,5.827944,-0.998953
>
> 7.582322,0.559370,0.411861
>
> 5.001753,3.279957,-0.148694
>
> ...
>
>
>
> of course my z's are different from yours, but this shouldn't be a
>
> real problem --- and here it is my *tested* solution (tested on python
>
> 2.7, that is), please feel free to adapt to your needs
>
>
>
> hth, ciao
>
> g
>
>
>
> % cat contour.py
>
> from numpy import loadtxt, linspace
>
> from matplotlib.mlab import griddata
>
> import matplotlib.pyplot as pl
>
>
>
> # open 'a.csv', specify the delimiter, specify how many header rows,
>
> # slurp the data
>
> temp_array = loadtxt(open('a.csv'),delimiter=',',skiprows=1)
>
>
>
> # the shape of temp_array is (N,3), we want its transpose
>
> temp_array = temp_array.transpose()
>
>
>
> # now the shape is (3,N) and we can do "unpack and assignment:
>
> x, y, z = temp_array
>
>
>
> # now the tricky part,
>
>
>
> # 1: create two arrays with 101 (arbitrary number) equispaced values
>
> # between 0 and 10 --- that is the ranges of data x and data y
>
> xi = linspace(0,10,101)
>
> yi = linspace(0,10,101)
>
>
>
> # 2: create, by interpolation, the 2D array that contourf so eagerly
>
> # awaited!
>
> print griddata.__doc__
>
> zi = griddata(x,y,z, xi,yi)
>
>
>
> # eventually, lets plot the stuff...
>
> # see http://matplotlib.org/examples/pylab_examples/griddata_demo.html
>
> # for further details and ideas
>
>
>
> pl.contour (xi,yi,zi,11,linewidths=1,colors='black')
>
> pl.contourf(xi,yi,zi); pl.colorbar()
>
> # optional
>
> pl.gca().set_aspect('equal', 'box')
>
> pl.show()
>
> % python contour.py
This is great and works very well - thank you!!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-14 08:22 -0700
Re: Matplotlib Contour Plots Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-15 02:53 +1000
Re: Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-15 04:54 -0700
Re: Matplotlib Contour Plots Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-15 23:23 +1000
Re: Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-15 07:42 -0700
Re: Matplotlib Contour Plots Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-16 01:13 +1000
Re: Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-18 09:51 -0700
Re: Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-18 09:55 -0700
Re: Matplotlib Contour Plots Rustom Mody <rustompmody@gmail.com> - 2014-08-18 10:16 -0700
Re: Matplotlib Contour Plots Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-19 10:10 +1000
Re: Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-19 01:43 -0700
Re: Matplotlib Contour Plots Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-08-19 09:12 -0400
Re: Matplotlib Contour Plots pecore@pascolo.net - 2014-08-19 23:21 +0200
Re: Matplotlib Contour Plots Jamie Mitchell <jamiemitchell1604@gmail.com> - 2014-08-20 03:02 -0700
Re: Matplotlib Contour Plots Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-20 17:55 +0100
Re: Matplotlib Contour Plots Christian Gollwitzer <auriocus@gmx.de> - 2014-08-18 19:49 +0200
Re: Matplotlib Contour Plots Anssi Saari <as@sci.fi> - 2014-08-18 13:37 +0300
csiph-web