Hey guys,

Thank you so much for your clear answers which have been very helpful!

Pawel

-----Wiadomość oryginalna-----
Od: Paul Ivanov [mailto:pivanov...@gmail.com] 
Wysłano: Thursday, December 23, 2010 3:03 PM
Do: matplotlib-users@lists.sourceforge.net
DW: Pawel Janowski
Temat: Re: ODP: [Matplotlib-users] starting with pplots

Pawel Janowski, on 2010-12-23 10:09,  wrote:
> Hi Pavel,
> 
> Thanks for your help. Matplotlib seems to be a really cool tool. Your 
> response almost answered my question. What I want is for the 3D plot 
> to be 2D. I mean the z-axis can only take on 5 discreet values so I 
> don't want to visualize 3 dimensions but just two with the data points 
> colored five different colors depending on the z value.

Pawel,

(I'm replying back to the list, so that others may benefit - hello there,
search engine visitors from the future!)

In that case, you can either follow Goya's suggestion - if you only want to
draw points. scatter will actually rescale the color values you give to
whatever colormap you're using - and for your case, with just five z values
in range(1,6), I found a slight tweak to the 'hsv' colormap does the trick.

  from numpy.random import rand, randint
  import matplotlib.pyplot as plt
  x,y = rand(2,100)
  z = randint(1,6,100)
  plt.scatter(x,y,c=z, vmin=-1, cmap=plt.get_cmap('hsv'))

You can see the built-in colormaps here:
http://matplotlib.sourceforge.net/examples/pylab_examples/show_colormaps.htm
l

and as Goyo showed, it's pretty easy to make a new one.

If you want more control, such as changing the shape of the marker, not just
the color, or if there's some order to your points that you want to also see
(for example, draw lines between points of the same z value) - you can use a
boolean mask. 

  from numpy.random import rand, randint
  import matplotlib.pyplot as plt
  x,y = rand(2,100)
  z = randint(1,6,100)
  for i,c,m in zip(range(1,6),'rgbmk', 'odp*s'):
      mask = z==i
      plt.plot(x[mask],y[mask], color=c, marker=m)

hope that helps,
--
Paul Ivanov
314 address only used for lists,  off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 


------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to