[AstroPy] scatter plot+colorbar

gonghang.naoc ghang.naoc at gmail.com
Thu Jun 4 10:43:19 EDT 2015


Thanks, Eric.
I find the  norm method here, but unfortunately it does not work.
http://matplotlib.1069221.n5.nabble.com/cmap-normalization-question-td16253.html
nm = matplotlib.colors.Normalize(desired_min, desired_max)
plt.scatter(x1,y1,c=myarr1,cmap=plt.get_cmap("gist_heat"),norm=nm)


On Thu, Jun 4, 2015 at 10:17 PM, Eric L. N. Jensen <ejensen1 at swarthmore.edu>
wrote:

> Hi Hang,
>
> What is the range of values of your ‘colorvalue’ column?   You may need to
> renormalize them to match the range expected by the ‘c’ argument to scatter
> (which I think is 0 to 1).  I think you can do this with the ’norm’
> argument to scatter, but I don’t know the syntax.
>
> Hope this helps -
>
> Eric
>
>
>
> On Jun 4, 2015, at 9:49 AM, gonghang.naoc <ghang.naoc at gmail.com> wrote:
>
> Hi all,
> I have a three column data set, x, y, and colorvalue. How to show the
> colorvalue for every point?
>
> I tried the code below, but it does not work.  The colorbar appears, but
> all points have the same color.
>
> #############
> import numpy as np
> import pylab as pl
>
> x,y,colorvlaue=np.loadtxt(dataset',usecols=(0,1,2),delimiter=",",unpack=True)
> pts=pl.scatter(x,y,s=0.1,c=colorvalue,cmap=pl.cm.jet)
> cb = pl.colorbar(pts)
>
> cmin,cmax = cb.get_clim()
> ticks = np.linspace(cmin,cmax,10)
> cb.set_ticks(ticks)
>
> pl.show()
> ################
> Could anybody specify the error in the code above?
>
> Thank you.
> Hang
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20150604/f7e34e9d/attachment.html>


More information about the AstroPy mailing list