473,740 Members | 9,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use matplotlib contour()?

I downloaded examples/contour_demo.py , and it doesn't run.

I've searched both the user guide and the Wiki for "contour"
and got zero hits.

http://matplotlib.sourceforge.net/ma....html#-contour
appears to be a good reference if you already know how to use
contour(), but I could glean zero clues from it on how to
actually use contour(). For example, it doesn't explain what
the actual formats/types of the parameters. It explains what
the parameters do, but not what they _are_

For example one parameter is specied as "an array". No clue as
to how many dimensions or what the axis are.

In another place it says "the X,Y parameters specify the (x,y)
coordinates of a surface". _How_ do they specify the surface?
Are they just equal length lists of x and y coordinates that
specify len(X) points. Or do they specify a len(X) x len(Y)
grid of points?

Since I can't find any documentation, I thought I'd just try a
few things.

I've got X,Y,Z values in an Nx3 array named "data" that looks
like this:

X Y Z
[[ 4.94958000e+01 3.65706000e+00 1.84600000e-01]
[ 4.94958000e+01 3.66447000e+00 1.82142000e-01]
[ 4.94958000e+01 5.04936000e+00 1.90937000e-01]
...,
[ 2.19844000e+03 9.74210000e+00 8.29735000e-01]
[ 2.19844000e+03 9.93863000e+00 9.82307000e-01]
[ 2.19844000e+03 1.03143000e+01 8.28844000e-01]]

If I just pass the array to contour() by doing
"pylab.contour( data)" I get this error:

Traceback (most recent call last):
File "./surfplot.py", line 11, in ?
pylab.contour(d ata)
File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 1659, in contour
ret = gca().contour(* args, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line 1244, in contour
return self._contourHe lper.contour(*a rgs, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 727, in contour
x, y, z, lev = self._contour_a rgs(False, badmask, origin, extent, *args)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 544, in _contour_args
lev = self._autolev(z , 7, filled, badmask)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 471, in _autolev
lev = linspace(zmin, zmax, N+2)[1:-1]
File "/usr/lib/python2.4/site-packages/matplotlib/mlab.py", line 87, in linspace
dx = (xmax-xmin)/(N-1)
TypeError: unsupported operand type(s) for -: 'str' and 'str'

I've no clue what that means. Well, I know what the TypeError
means _literally_, but I've no idea how I'm supposed to
interpret that particular error in regards to what I passed to
contour().

Attempting to use one of the other forms found on the above web
page I pass X,Y,Z vectors to contour() by doing
"pylab.contour( data[:,0],data[:,1],data[:,2])":

Traceback (most recent call last):
File "./surfplot.py", line 13, in ?
pylab.contour(d ata[:,0],data[:,1],data[:,2])
File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 1659, in contour
ret = gca().contour(* args, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line 1244, in contour
return self._contourHe lper.contour(*a rgs, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 727, in contour
x, y, z, lev = self._contour_a rgs(False, badmask, origin, extent, *args)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 539, in _contour_args
x,y,z = self._check_xyz (args[:3])
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 515, in _check_xyz
raise TypeError("Inpu t z must be a 2D array.")
TypeError: Input z must be a 2D array.

Which is almost as cryptic a result as my first attempt.

Why would my Z values be a 2D array?

--
Grant Edwards grante Yow! My NOSE is NUMB!
at
visi.com
May 24 '06 #1
2 11650
Grant Edwards wrote:
I downloaded examples/contour_demo.py , and it doesn't run.

I've searched both the user guide and the Wiki for "contour"
and got zero hits.

http://matplotlib.sourceforge.net/ma....html#-contour
appears to be a good reference if you already know how to use
contour(), but I could glean zero clues from it on how to
actually use contour(). For example, it doesn't explain what
the actual formats/types of the parameters. It explains what
the parameters do, but not what they _are_
Yes, unfortunately, much of the documentation was written by people who were
very familiar with the Matlab interfaces that these functions are emulating.
For example one parameter is specied as "an array". No clue as
to how many dimensions or what the axis are.

In another place it says "the X,Y parameters specify the (x,y)
coordinates of a surface". _How_ do they specify the surface?
Are they just equal length lists of x and y coordinates that
specify len(X) points. Or do they specify a len(X) x len(Y)
grid of points? Why would my Z values be a 2D array?


contour() only does contouring on gridded data. If you want to handle scattered
datapoints, you will have to do some interpolation.

http://www.scipy.org/Cookbook/Matplo...ly_spaced_data

So X, Y, and Z are all 2-D arrays laid out corresponding to the grid that you
have sampled. I thought the contour_demo.py example was reasonably clear on
this, but if you didn't get it to run, then I can see why you wouldn't have read it.

Talking about this on matplotlib-users will probably get these problems fixed
faster:

https://lists.sourceforge.net/lists/...tplotlib-users

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

May 24 '06 #2
On 2006-05-24, Robert Kern <ro*********@gm ail.com> wrote:
Yes, unfortunately, much of the documentation was written by people who were
very familiar with the Matlab interfaces that these functions are emulating.
Since I've never used matlab, I'm a bit clueless.
For example one parameter is specied as "an array". No clue as
to how many dimensions or what the axis are.

In another place it says "the X,Y parameters specify the (x,y)
coordinates of a surface". _How_ do they specify the surface?
Are they just equal length lists of x and y coordinates that
specify len(X) points. Or do they specify a len(X) x len(Y)
grid of points?

Why would my Z values be a 2D array?


contour() only does contouring on gridded data.


That's what I was beginning to suspect. What confused me was
that if it required gridded data, I expected the input parameters to
specify a grid (e.g. for a 5x7 grid, the X parameter would be a
vector of 5 values, and the Y parameter would be a vector of 7
values) rather than just lie on a grid.
If you want to handle scattered datapoints, you will have to
do some interpolation.

http://www.scipy.org/Cookbook/Matplo...ly_spaced_data
Thanks, that looks like exactly what I need. My next step was
actually going to be to use the Delaunay triangulation module
to interpolate the data onto a much finer grid.
So X, Y, and Z are all 2-D arrays laid out corresponding to
the grid that you have sampled. I thought the contour_demo.py
example was reasonably clear on this, but if you didn't get it
to run, then I can see why you wouldn't have read it.
I did delete some code that was attempting to label the graph,
and then it ran. The examples do use gridded data, but when I
changed them to non-gridded data, it seemed to run fine.
Talking about this on matplotlib-users will probably get these
problems fixed faster:

https://lists.sourceforge.net/lists/...tplotlib-users


After I got the demos to run, it became apparent that the
contour functions don't do what I want anyway, so it's all moot
at this point.

--
Grant Edwards grante Yow! YOW!! Now I
at understand advanced
visi.com MICROBIOLOGY and th' new
TAX REFORM laws!!
May 25 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1770
by: John Hunter | last post by:
matplotlib is a 2D plotting package for python with a matlab compatible syntax and output tested under linux and windows platforms. matplotlib-0.30 is available for download at http://matplotlib.sourceforge.net, and has many new features since the last major release. Multiple outputs matplotlib now supports postscript and GD output, as well as the
3
2624
by: John Hunter | last post by:
matplotlib is a 2D plotting library for python. You can use matplotlib interactively from a python shell or IDE, or embed it in GUI applications (WX, GTK, and Tkinter). matplotlib supports many plot types: line plots, bar charts, log plots, images, pseudocolor plots, legends, date plots, finance charts and more. What's new since matplotlib 0.50 This is the first wide release in 5 months and there has been a tremendous amount of...
2
6675
by: scott | last post by:
I am trying to convert a python app that uses matplotlib to a standalone executable using py2exe. After running py2exe and executing my app I get the following stack trace: Traceback (most recent call last): File "gcToCsv.py", line 5, in ? File "plot_output.pyc", line 1, in ? File "pylab.pyc", line 1, in ?
0
2597
by: spross | last post by:
hi all i have to use matplotlib on mac os x. on the official site of matplotlib, i found a link to precompiled python packages for mac os x: http://pythonmac.org/packages/py24-fat/index.html so first, i installed python 2.4. that works great! if i type 'python' in the terminal, it loads python 2.4. after that, i loaded and installed the matplotlib package from this
0
3403
by: Soren | last post by:
Hi, I've been trying to embed matplotlib in wxpython. I want to be able to put a figure (axes) in a wx.Panel and place it somewhere in my GUI. The GUI should have other panels with buttons etc. that can control the output on the figure. I've been looking at the examples from the matplotlib website, but can't seem to get it to work.. Does anyone here have experience in embedding matplotlib in wxpython?
4
3351
by: Bill Jackson | last post by:
Hi, I'm having some trouble plotting with the following matplotlibrc: text.usetex : True I tried clearing the cache files under ~/.matplotlib, but this did not help the problem. I'd post on the matplotlib mailing list, but I have a hard enough time browsing sourceforge's achives (frequent internal server errors). Here is some output:
3
4721
by: vajratkarviraj | last post by:
i hav python2.5, matplotlib0.90.1, and py2exe for python 2.5 all on windows xp... i hav a python program(letsc.py) which uses the matplotlib package... and i want 2 make an exe of it for distribution on other comps... i used py2exe... i wrote a setup.py whose contents are : from distutils.core import setup import py2exe import matplotlib setup(console=, options={ 'py2exe': { 'packages' : ,
4
9689
by: John Henry | last post by:
Has anybody been able to create an exe of their python applications involving matplotlib using pyinstall (ver 1.3)? I am getting a: RuntimeError: Could not find the matplotlib data files when I attempt to run the exe created. In searching the web, it appears this is an issue when others tried to use py2exe as well. Unfortunately, the few hits I saw doesn't include enough details to inspire me as to what I should be doing in my
0
4331
by: PamMish1982 | last post by:
Hi all, I have recently started using Python and I am trying to make a GUI out of Tkinter. I am using matplotlib for the graphic purposes. I have to make a exe file from this code. I use py2exe for this purpose but every time I try to make this exe using a setup file I get these errors. Final.py is my python code. Traceback (most recent call last): File "Final.py", line 5, in <module> File "pylab.pyc", line 1, in <module> File...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8794
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9484
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9211
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6756
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4572
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3286
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2195
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.