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


Groups > comp.lang.python > #76369

Re: Matplotlib Contour Plots

Newsgroups comp.lang.python
Date 2014-08-15 07:42 -0700
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>
Message-ID <c3ca3710-a481-43c2-a2b8-e4105d7160ac@googlegroups.com> (permalink)
Subject Re: Matplotlib Contour Plots
From Jamie Mitchell <jamiemitchell1604@gmail.com>

Show all headers | View raw


On Friday, August 15, 2014 2:23:25 PM UTC+1, Steven D'Aprano wrote:
> Jamie Mitchell wrote:
> 
> 
> 
> [...]
> 
> > I just want to get a contour plot of two numpy arrays.
> 
> > When I call plt.contour on my data I get "input must be a 2D array"
> 
> 
> 
> You are providing a 1D array, or possibly a 3D array. So the question you
> 
> really want to ask is not "How do I do contour plots" but "how do I make a
> 
> 2D array?"
> 
> 
> 
> 
> 
> > An example of one of my arrays:
> 
> > 
> 
> > array([ 2.08800006,  2.29400015,  2.00400019,  1.88000011,  2.0480001 ,
> 
> >         2.16800022,  2.0480001 ,  1.88200009,  1.95800006,  2.00200009,
> 
> >         2.02800012,  1.81200004,  1.95000005,  1.96200013,  1.95200014,
> 
> >         1.99800014,  2.07000017,  1.88200009,  1.98400009,  2.13400006,
> 
> >         2.11400008,  1.89400005,  2.05000019,  2.01999998,  2.03400016,
> 
> >         2.16600013,  2.00999999,  1.86200011,  2.19800019,  2.01200008],
> 
> >         dtype=float32)
> 
> > 
> 
> > How do I get the above array in to the right format for a contour plot?
> 
> 
> 
> Here's an example of making a 2D array:
> 
> 
> 
> py> import numpy
> 
> py> a = numpy.array([1.2, 2.5, 3.7, 4.8])  # One dimensional array
> 
> py> a
> 
> array([ 1.2,  2.5,  3.7,  4.8])
> 
> py> b = numpy.array([ [1.2, 2.5, 3.7, 4.8], 
> 
> ...                   [9.5, 8.1, 7.0, 6.2] ])  # Two dimensional array
> 
> py> b
> 
> array([[ 1.2,  2.5,  3.7,  4.8],
> 
>        [ 9.5,  8.1,  7. ,  6.2]])
> 
> 
> 
> One dimensional arrays are made from a single list of numbers: [...]
> 
> 
> 
> Two dimensional arrays are made from a list of lists: [ [...], [...] ]
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Steven

Thank you Steven.

I created the 2D array which read as:

array([[[ 2.08800006,  2.29400015,  2.00400019,  1.88000011,  2.0480001 ,
          2.16800022,  2.0480001 ,  1.88200009,  1.95800006,  2.00200009,
          2.02800012,  1.81200004,  1.95000005,  1.96200013,  1.95200014,
          1.99800014,  2.07000017,  1.88200009,  1.98400009,  2.13400006,
          2.11400008,  1.89400005,  2.05000019,  2.01999998,  2.03400016,
          2.16600013,  2.00999999,  1.86200011,  2.19800019,  2.01200008]],

       [[ 8.5199995 ,  8.88000011,  8.55000019,  7.94999981,  8.60999966,
          8.5199995 ,  8.80000019,  8.13000011,  8.68999958,  8.72999954,
          8.47999954,  8.25      ,  8.40999985,  8.43999958,  8.38999939,
          8.35999966,  8.63999939,  8.51000023,  8.36999989,  8.69999981,
          8.52999973,  8.13999939,  8.36999989,  8.42000008,  8.55999947,
          8.72999954,  9.09000015,  8.18999958,  8.76000023,  8.53999996]]], dtype=float32)

Unfortunately when I called plt.contour on this, it said again "Input must be a 2D array".

Is there something I have missed?

Thanks,

Jamie

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