APLpy show markers normalized by a colormap

北慕城南 提交于 2019-12-12 02:52:26

问题


I am using APLpy to plot a fits file and want to overplot markers on that fits file at certain ra,dec values. I want the colours of the markers to be coded with another parameter, lets say a magnitude.

So what I do is I read the marker coordinates and the corresponding magnitudes from a textfile (positions.dat):

ra         = np.genfromtxt('positions.dat', dtype=float, comments='%', delimiter=';', missing_values='_', skip_header=1, usecols = (0))                                 
dec        = np.genfromtxt('positions.dat', dtype=float, comments='%', delimiter=';', missing_values='_', skip_header=1, usecols = (1))                                 
magnitude  = np.genfromtxt('positions.dat', dtype=float, comments='%', delimiter=';', missing_values='_', skip_header=1, usecols = (2))                                   

I define a colormap and its normalization:

cmap1 = mpl.cm.YlOrBr                                                           
norm1 = mpl.colors.Normalize(10,20)                                                           

My magnitudes in the positions.dat file are all between 10 and 20 to test the code.

I tried to plot the markers as follows:

fits1.show_markers(ra,dec, cmap=cmap1, norm=norm1, edgecolor=magnitude, facecolor='none', marker='x', s= 4, linewidths=0.8)

When I do this, I always get the error:

ValueError: Color array must be two-dimensional

The positions.dat file looks like that:

  ra    ;      dec     ;   magnitude
330.45  ;  -31.958333  ;      10.0
330.46  ;  -31.958333  ;      11.0
330.47  ;  -31.958333  ;      12.0
330.48  ;  -31.958333  ;      13.0
330.49  ;  -31.958333  ;      14.0
330.50  ;  -31.958333  ;      15.0
330.51  ;  -31.958333  ;      16.0
330.52  ;  -31.958333  ;      17.0
330.53  ;  -31.958333  ;      18.0
330.54  ;  -31.958333  ;      19.0
330.55  ;  -31.958333  ;      20.0

回答1:


The issue is that matplotlib's scatter can't take values for edgecolor and facecolor that are not color arrays (that is, arrays of RGB values). The correct way to achieve what you are trying to do is to use scatter's c argument, so in this case:

fits1.show_markers(ra,dec, cmap=cmap1, norm=norm1,
                   c=magnitude, facecolor='none',
                   marker='x', s=4, linewidths=0.8)


来源:https://stackoverflow.com/questions/25902162/aplpy-show-markers-normalized-by-a-colormap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!