pcolor or contour

hi i have been trying to use pcolor and/or contour to make a contor map
or intensity map
i want to do an intensity or contour map of an electric field
i have an array (or list) of points [x,y] and for each point i have the respective value of the electric field (in another list)

i have tried the examples in matplotlib but they are different because they use meshgrid
and from the points calculated in the mesh get values and plot…
in my case i want to plot directly…each poin (x,z) its magnitude(E_fiel_Mag)
i do not think i need to use meshgrid any more how can i do my plot?
below is my
code…pls help me!!!

#!/usr/bin/env python

This example demonstrates how to use a constraint polygon in

Delaunay triangulation.

from scipy import*
from pylab import*

read_file= open (‘W:/Serio/necfile.out’,‘r’)

L =read_file.readlines()

fieldlist =[]
f = 0
for line in L:

            rpoints = 3
            phipoints = 3
             tetapoints =


            for line in range (f+3,f+4+rpoints*phipoints*tetapoints):

Ex = [];Ey = [];Ez = []
x1 =[];y1=[];z1=[]
Exphase=[]; Eyphase=[]; Ezphase=[]

for i in range(len(fieldlist)-1):

    splitlines= fieldlist[i].split()

    x1.append(float(splitlines[0]))     #here we pick up the x,y,x coordinates of the points
    y1.append(float(splitlines[1]))     #where the manitude has been calculated

    Ex.append(float(splitlines[3]))     #pick up the e-filed magnitudes
    Ey.append(float(splitlines[5]))     #u append as floats instead os string for later calculations

    Exphase.append(float(splitlines[4])) # pick up the phases just in case they are needed


i want to see if i can calculate the magnitude of the electric field

E_field_Mag = []
for i in range(len(Ex)):
E_Magnitude = sqrt((Ex[i])**2 + (Ey[i])**2+(Ez[i])**2)

#E_field_Mag = array(E_field_Mag)

#y values are zero
#X,Z = meshgrid(x1, z1)


contourin2.py (1.79 KB)


----- Mensaje original ----
De: “matplotlib-users-request@…1753…forge.net” matplotlib-users-request@lists.sourceforge.net
Enviado: domingo, 30
de septiembre, 2007 12:53:11
Asunto: Matplotlib-users Digest, Vol 16, Issue 32

Send Matplotlib-users mailing list submissions to

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body ‘help’ to

You can reach the person managing the list at

When replying, please edit your Subject line so it is more specific
than “Re: Contents of Matplotlib-users digest…”

Today’s Topics:

1. Re: NameError: global name '__loader__' is not

(Eric Firing)
2. Re: plot cdf (Alan G Isaac)
3. Re: edgecolor with usetex=True, usedistiller=‘pdf’ (Darren Dale)
4. Re: Problem with tick labels in scripts (John Hunter)
5. Using special characters (David Loyall)
6. Re: matplotlib - representation of nan values in 2D
(Dirk Zickermann)

Message: 1
Date: Thu, 27 Sep 2007 14:46:13 -1000
From: Eric Firing <efiring@…202…>
Subject: Re: [Matplotlib-users] NameError: global name ‘loader’ is
not defined
To: Hal Huntley <hal@…1718…>
Cc: matplotlib-users@lists.sourceforge.net
Message-ID: <46FC4ED5.1060005@…202…>
text/plain; charset=ISO-8859-1; format=flowed

Hal Huntley wrote:

Thanks to Eric Firing and Christopher Barker for input on trying to
resolve the problem. Christopher said:
You might try just:

easy_install numpy

easy_install matplotlib.

I did that and now the problem moved and I get:

from pylab import *
Traceback (most recent call last):
File “”, line 1, in ?
“/usr/lib/python2.4/site-packages/matplotlib-0.90.1-py2.4-linux-i686.egg/pylab.py”, line 1, in ?
from matplotlib.pylab import *
“/usr/lib/python2.4/site-packages/matplotlib-0.90.1-py2.4-linux-i686.egg/matplotlib/pylab.py”, line 222, in ?

new_figure_manager, draw_if_interactive, show = pylab_setup()

“/usr/lib/python2.4/site-packages/matplotlib-0.90.1-py2.4-linux-i686.egg/matplotlib/backends/init.py”, line 24, in pylab_setup
“/usr/lib/python2.4/site-packages/matplotlib-0.90.1-py2.4-linux-i686.egg/matplotlib/backends/backend_gtkagg.py”, line 10, in ?
from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK,
“/usr/lib/python2.4/site-packages/matplotlib-0.90.1-py2.4-linux-i686.egg/matplotlib/backends/backend_gtk.py”, line 21, in ?
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK

“/usr/lib/python2.4/site-packages/matplotlib-0.90.1-py2.4-linux-i686.egg/matplotlib/backends/backend_gdk.py”, line 35, in ?

from matplotlib.backends._ns_backend_gdk import pixbuf_get_pixels_array

ImportError: No module named _ns_backend_gdkd4

Is it a rotten egg?

Googling around has indicated that the X11 stuff wasn’t available when the
numpy and matplotlib were made. The gtk files and “-devel” seem to be there
when I do an “rpm -qa”. I went and got a new numpy from source and did
“python setup.py install”. It is interesting that when I get in to python
now, I can do:

import gtk
import numpy
import matplotlib

and they all just return the prompt, indicating, I thought, that the
programs were installed ok.

Here is the naive question -> Is there something wrong, then with a
“from pylab import *”? The user is trying to do that.

No, that should work fine. I don’t know how the egg-based
matplotlib/pylab should work with the installed-from-source numpy,
though. If the versions are compatible, then I expect it would work.

You gave a traceback resulting from “from pylab import *” after
installing the two eggs, correct? If so, what was the result after you
installed numpy from source? I would expect no difference, because the
problem reported in the traceback is a missing matplotlib module, not a
missing numpy module.

Or did you mean that you installed matplotlib from source? That would
make more sense, and certainly should work if all the right header files
and libraries are present.

If you installed matplotlib from
source, what do you get from
ls /usr/lib/python2.4/site-packages/matplotlib/backends/*.so

Another diagnostic would be to delete the build directory from the
matplotlib source tree (assuming you are now building matplotlib from
source), and save the output from the “python setup.py build” command.
This should make it clear whether the necessary headers really were found.


Message: 2
Date: Fri, 28 Sep 2007 00:18:13 -0400
From: Alan G Isaac <aisaac@…310…>
Subject: Re: [Matplotlib-users] plot cdf
To: matplotlib-users@lists.sourceforge.net
Message-ID: <Mahogany-0.67.0-1032-20070928-001813.00@…310…>

After thinking it over, I did not go for
Robert or David’s cool numpy tricks, but
I’ll append a simple object in case someone
else wants to do more.


class EmpiricalCDF(object):
‘’‘Empirical cdf.
First point will be (xmin,0).
Last point will be (xmax,1).
def init(self, data, sortdata=True):
if sortdata:
data = N.sort(data)
self.data = data
self.nobs = len(data)
def gen_xp(self):
data, nobs = self.data, self.nobs
prob = N.linspace(0, 1, nobs+1)
xsteps = ( data[(idx)//2] for idx in xrange(2nobs)
psteps = ( prob[(idx+1)//2] for idx in xrange(2
nobs) )
return xsteps, psteps
def get_steps(self):
‘’‘Return: 2-tuple of arrays,
the data values and corresponding cumulative
xsteps, psteps = self.gen_xp()
return N.fromiter(xsteps,‘f’), N.fromiter(psteps,‘f’)

Message: 3
Date: Fri, 28 Sep 2007 08:23:17 -0400
From: Darren Dale <dd55@…163…>
Subject: Re: [Matplotlib-users] edgecolor with
To: “John Hunter” <jdh2358@…287…>
Cc: matplotlib-users matplotlib-users@lists.sourceforge.net, Eric
Firing <efiring@…202…>
Message-ID: <200709280823.17560.dd55@…163…>
Content-Type: text/plain; charset=“iso-8859-1”

On Friday 28 September 2007 07:36:23 am John Hunter wrote:

On 9/27/07, Darren Dale <dd55@…163…> wrote:

Hi Eric, John,

Have either of you been following this thread?

I am now :slight_smile:

As Eric suggests, None is overloaded vis-a-vis color handling, because
for mpl properties it generally means do the default as defined by rc.
For colors people often want to use None for “no color” which is why
we added support for the string “None”. Does
this work in your use
case Tom?

The above exchange was off-list, we’re back on now. I think that would be what
Tom is looking for, but it doesnt work:

In [1]: plot([1,2])
Out[1]: [<matplotlib.lines.Line2D instance at 0x710cb0>]

In [2]: savefig(‘dsd.png’, facecolor=‘None’, edgecolor=‘None’)

ValueError Traceback (most recent call last)

/home/darren/ in ()

/usr/lib64/python2.5/site-packages/matplotlib/pyplot.py in savefig(*args,
272 def savefig(*args, **kwargs):
273 fig = gcf()
274 return fig.savefig(*args, **kwargs)
275 if Figure.savefig.doc is not None:
276 savefig.doc = dedent(Figure.savefig.doc)

/usr/lib64/python2.5/site-packages/matplotlib/figure.py in savefig(self,
*args, **kwargs)
768 kwargs[key] = rcParams[‘savefig.%s’%key]
–> 770 self.canvas.print_figure(*args, **kwargs)
772 def colorbar(self, mappable, cax=None, **kw):

/usr/lib64/python2.5/site-packages/matplotlib/backends/backend_qt4agg.py in
print_figure(self, *args,
153 self.update(l, self.renderer.height-t, w, h)
155 def print_figure(self, *args, **kwargs):
–> 156 FigureCanvasAgg.print_figure(self, *args, **kwargs)
157 self.draw()

/usr/lib64/python2.5/site-packages/matplotlib/backend_bases.py in
print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format,
1194 edgecolor=edgecolor,
1195 orientation=orientation,
1196 **kwargs)
1197 finally:
1198 self.figure.dpi.set(origDPI)

/usr/lib64/python2.5/site-packages/matplotlib/backends/backend_agg.py in
print_png(self, filename, *args, **kwargs)
416 def print_png(self, filename, *args, **kwargs):
–> 417 self.draw()
418 self.get_renderer()._renderer.write_png(str(filename))

/usr/lib64/python2.5/site-packages/matplotlib/backends/backend_qt4agg.py in

140 if DEBUG: print “FigureCanvasQtAgg.draw”, self
141 self.replot = True
–> 142 FigureCanvasAgg.draw(self)
143 self.update()

/usr/lib64/python2.5/site-packages/matplotlib/backends/backend_agg.py in
378 self.renderer = self.get_renderer()
–> 379 self.figure.draw(self.renderer)
381 def get_renderer(self):

/usr/lib64/python2.5/site-packages/matplotlib/figure.py in
586 self.transFigure.freeze() # eval the lazy objects
–> 588 if self.frameon: self.figurePatch.draw(renderer)
590 for p in self.patches: p.draw(renderer)

/usr/lib64/python2.5/site-packages/matplotlib/patches.py in draw(self,
198 #renderer.open_group(‘patch’)
199 gc = renderer.new_gc()
–> 200 gc.set_foreground(self._edgecolor)
202 gc.set_alpha(self._alpha)

/usr/lib64/python2.5/site-packages/matplotlib/backend_bases.py in
set_foreground(self, fg, isRGB)
617 self._rgb = fg
618 else:
–> 619 self._rgb = colors.colorConverter.to_rgb(fg)
621 def set_graylevel(self, frac):

/usr/lib64/python2.5/site-packages/matplotlib/colors.py in to_rgb(self, arg)
278 except (KeyError, ValueError, TypeError), exc:
279 raise ValueError(‘to_rgb: Invalid rgb arg “%s”\n%s’ %
(str(arg), exc))
280 # Error messages could be improved by handling TypeError
281 # separately; but this should be rare and not too hard

ValueError: to_rgb: Invalid rgb arg “None”
invalid literal for float(): None

Message: 4
Date: Fri, 28 Sep 2007 07:41:35 -0500
From: “John Hunter” <jdh2358@…287…>
Subject: Re: [Matplotlib-users] Problem with tick labels in scripts
To: “Charles Seaton” <cseaton@…1754…>
Content-Type: text/plain; charset=ISO-8859-1

On 9/27/07, Charles Seaton <cseaton@…1743…> wrote:

I am having the same problem as Eugen, and the suggested solution of using
to force the creation of the full set of ticklabels doesn’t seem to work for

matplotlib creates a prototypical tick (the prototick) and then
creates new ones on as as needed basis, copying properties from the
prototick. Of course, position is one of the properties that cannot
be copied, which is why you are having trouble in your example.
Fortunately, there is an easy solution.

Call ax.xaxis.get_major_ticks() and access the label attribute:

for tick in ax.xaxis.get_major_ticks():

label = tick.label1

Axis.get_major_ticks will force a call to the locator and update the
tick list. The Axes methods like get_xticklabels are just working on
the existing tick list rather than calling the get_major_ticks method
which is why you are not getting the full list. This is a bug. I
just made changes in svn so that all the accessor methods
(ax.get_xticklines, ax.get_yticklabels, and friends) all trigger a
call to axis.get_major_ticks rather so they should give the same
results going forward.


FYI, the Tick attributes are:

  tick1line  : a Line2D instance
  tick2line  : a Line2D instance
  gridline   : a Line2D instance
   label1     : a Text

label2 : a Text instance
gridOn : a boolean which determines whether to draw the tickline
tick1On : a boolean which determines whether to draw the 1st tickline
tick2On : a boolean which determines whether to draw the 2nd tickline
label1On : a boolean which determines whether to draw tick label
label2On : a boolean which determines whether to draw tick label

Message: 5
Date: Sat, 29 Sep 2007 21:50:02 -0500
From: “David Loyall” <david.loyall@…1744…>
Subject: [Matplotlib-users] Using special characters
Content-Type: text/plain; charset=UTF-8


I’ve been having trouble getting Unicode characters to render. I just
get a box in the title of my figure, rather than the character I need.

Here is my code:
#!/usr/bin/env python
from pylab import *

That character is LATIN SMALL LETTER ALPHA. It’s used in the
International Phonetic Alphabet.

I’m on Linux and I’m using matplotlib 0.90.1-2 (debian package
version). I have a few TTF fonts in my system that contain that
glyph. One is ‘Arial Unicode MS’, which I copied from my windows

As you can see, I will need to generate an EPS that renders
character… That EPS file will be imported into MS Word on a Windows
PC and printed.

I will happily use any solution that allows me to use that character
in the final product… :slight_smile: It doesn’t have to be unicode…

I believe that my fonts are configured correctly on this Linux
system–I can use the Arial Unicode MS font in Open Office. However,
I’m not sure that MPL is finding them.

When I point the TTFPATH environment variable a directory that only
contains ARIALUNI.TTF, I get gibberish for all characters in my

When I use ~/.matplotlib/matplotlibrc to list Arial Unicode MS as the
only font in the san-serif family, I don’t observe any change in the
text in the figure.

…I did successfully instantiate an FT2FONT object out of my
ARIALUNI.TTF file, but, I didn’t know what to do with it at that


Omaha, Nebraska, USA

Message: 6
Date: Sun, 30 Sep 2007 12:53:06 +0200
From: “Dirk Zickermann” <dirk.zickermann@…982…>
Subject: Re: [Matplotlib-users] matplotlib - representation of nan
values in 2D
To: Matplotlib-users@…1064…t
Content-Type: text/plain; charset=“iso-8859-1”

Dear all,
thanks for your help. this is what I was looking for!

2007/9/26, Eric Firing <efiring@…878…202…>:

David Huard wrote:

Hi Dirk,

If you haven’t already done so, look at the numpy.ma <http://numpy.ma/>
module. It provides a masked array
object that
deals gracefully with

missing values. To the best of my knowledge, most matplotlib functions
understand masked arrays and deal with it accordingly, exception made of
those requiring a full matrix (such as contour). Take a look at

contour handles masked arrays correctly, as far as I know; contourf has
some bugs in its masked array handling, but depending on the type and
distribution of voids, it may still be good enough.

pcolor and image have no problems with masked arrays.


examples/image_masked.py. Also, in the Basemap toolkit, there is at
least one example showing how to plot a masked array on a map.



This SF.net email is sponsored by: Microsoft

Defy all challenges. Microsoft® Visual Studio 2005.


Matplotlib-users mailing list

-------------- next part --------------
An HTML attachment was scrubbed…

This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft® Visual Studio 2005.

Matplotlib-users mailing list

End of Matplotlib-users Digest, Vol 16, Issue 32

¡Sé un mejor asador!
Aprende todo sobre asados en: