From: elmar w. <el...@ne...> - 2012-10-19 19:17:41
|
Hi, is there a way to adjust the marker color in a xy-plot in relation to the value of a third parameter. Something as the following - not working - example 1. Example 2 is working but rather slow for large arrays. cheers Elmar # example 1 import matplotlib.pyplot as plt x = [1,2,3,4] y = x c = ((1.0, 0.0, 0.0), (0.8, 0.1, 0.1), (0.6, 0.2, 0.6), (0.4, 0.3, 0.3)) plt.plot(x,y, color=c, marker='s') plt.show() example 2: import matplotlib.pyplot as plt x = [1,2,3,4] y = x c = ((1.0, 0.0, 0.0), (0.8, 0.1, 0.1), (0.6, 0.2, 0.6), (0.4, 0.3, 0.3)) for i in range(len(x)): plt.plot(x[i], y[i], color=c[i], marker='s') plt.show() |
From: Joe K. <jki...@wi...> - 2012-10-19 19:59:25
|
That's what ``scatter`` is intended for. Basically, you want something like: plt.scatter(x, y, c=z, marker='s') plt.colorbar() Note that you can also vary the markers by size based on an additional parameter, as well. Have a look at this example: http://matplotlib.org/examples/pylab_examples/scatter_demo.html Hope that helps, -Joe On Fri, Oct 19, 2012 at 2:19 PM, elmar werling <el...@ne...> wrote: > Hi, > > is there a way to adjust the marker color in a xy-plot in relation to > the value of a third parameter. Something as the following - not working > - example 1. > > Example 2 is working but rather slow for large arrays. > > cheers > Elmar > > > > > # example 1 > > import matplotlib.pyplot as plt > > x = [1,2,3,4] > y = x > c = ((1.0, 0.0, 0.0), (0.8, 0.1, 0.1), (0.6, 0.2, 0.6), (0.4, 0.3, 0.3)) > > plt.plot(x,y, color=c, marker='s') > plt.show() > > > example 2: > > import matplotlib.pyplot as plt > > x = [1,2,3,4] > y = x > c = ((1.0, 0.0, 0.0), (0.8, 0.1, 0.1), (0.6, 0.2, 0.6), (0.4, 0.3, 0.3)) > > for i in range(len(x)): > plt.plot(x[i], y[i], color=c[i], marker='s') > > plt.show() > > > > ------------------------------------------------------------------------------ > Everyone hates slow websites. So do we. > Make your web apps faster with AppDynamics > Download AppDynamics Lite for free today: > http://p.sf.net/sfu/appdyn_sfd2d_oct > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |
From: elmar w. <el...@ne...> - 2012-10-19 21:19:16
|
thanks for help, finally I found the following solution elmar import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt N = 200 x = np.linspace(0,1,N) y = np.random.randn(N) z = np.random.randn(N)*2+5 cm = mpl.cm.get_cmap('RdYlBu') sc = plt.scatter(x, y, c=z, vmin=min(z), vmax=max(z), s=35, cmap=cm) plt.colorbar(sc) plt.show() Am 19.10.2012 21:59, schrieb Joe Kington: > plt.scatter(x, y, c=z, marker='s') > plt.colorbar() |
From: Daπid <dav...@gm...> - 2012-10-19 21:24:05
|
On Fri, Oct 19, 2012 at 11:08 PM, elmar werling <el...@ne...> wrote: > vmin=min(z), vmax=max(z) A suggestion, when dealing with arrays, it is generally faster to use the numpy function to compute the max and min, either np.max(z) or z.max(), than the standard Python one. |
From: Damon M. <dam...@gm...> - 2012-10-19 21:26:12
|
On Fri, Oct 19, 2012 at 10:23 PM, Daπid <dav...@gm...> wrote: > On Fri, Oct 19, 2012 at 11:08 PM, elmar werling <el...@ne...> wrote: >> vmin=min(z), vmax=max(z) > > A suggestion, when dealing with arrays, it is generally faster to use > the numpy function to compute the max and min, either np.max(z) or > z.max(), than the standard Python one. Correct me if I'm wrong, but I don't even think you need them. I think the default cmap behaviour is to normalise to the min and max of the data. -- Damon McDougall http://www.damon-is-a-geek.com B2.39 Mathematics Institute University of Warwick Coventry West Midlands CV4 7AL United Kingdom |
From: elmar w. <el...@ne...> - 2012-10-19 21:51:57
|
Am 19.10.2012 23:26, schrieb Damon McDougall: > Correct me if I'm wrong, but I don't even think you need them. I think > the default cmap behaviour is to normalise to the min and max of the > data. yes, default cmap behaviour will normalise to the min and max of the data. |