Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76651

Re: Matplotlib Contour Plots

X-Received by 10.236.207.164 with SMTP id n24mr23857589yho.5.1408528939431; Wed, 20 Aug 2014 03:02:19 -0700 (PDT)
X-Received by 10.140.33.203 with SMTP id j69mr755433qgj.2.1408528939413; Wed, 20 Aug 2014 03:02:19 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!m5no1336571qaj.0!news-out.google.com!j6ni3084qas.0!nntp.google.com!i13no1337052qae.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Wed, 20 Aug 2014 03:02:19 -0700 (PDT)
In-Reply-To <87iolo2n0z.fsf@pascolo.net>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=151.170.240.10; posting-account=4ZFvUQoAAADRMMFTP4AD3zzRxG7Xhtl3
NNTP-Posting-Host 151.170.240.10
References <e1bbdda8-47a8-4849-8180-1f1a08aeb059@googlegroups.com> <53ece976$0$29992$c3e8da3$5496439d@news.astraweb.com> <2f9537da-86b8-441d-a214-00123b8416d1@googlegroups.com> <53ee09cd$0$29994$c3e8da3$5496439d@news.astraweb.com> <c3ca3710-a481-43c2-a2b8-e4105d7160ac@googlegroups.com> <53ee2397$0$29966$c3e8da3$5496439d@news.astraweb.com> <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>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <408a7442-e9e0-4e78-b045-f0ea22284e6a@googlegroups.com> (permalink)
Subject Re: Matplotlib Contour Plots
From Jamie Mitchell <jamiemitchell1604@gmail.com>
Injection-Date Wed, 20 Aug 2014 10:02:19 +0000
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
Lines 160
Xref csiph.com comp.lang.python:76651

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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