[英]APLpy show markers normalized by a colormap
I am using APLpy to plot a fits file and want to overplot markers on that fits file at certain ra,dec values. 我正在使用APLpy绘制拟合文件,并希望以一定的ra,dec值在该拟合文件上过度绘制标记。 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): 所以我要做的是从文本文件(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. 我在positions.dat文件中的大小都在10到20之间,以测试代码。
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: positions.dat文件如下所示:
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
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). 问题在于,matplotlib的散点图不能采用非颜色数组(即RGB值数组)的
edgecolor
和facecolor
值。 The correct way to achieve what you are trying to do is to use scatter's c
argument, so in this case: 实现您要尝试执行的操作的正确方法是使用散点图的
c
参数,因此在这种情况下:
fits1.show_markers(ra,dec, cmap=cmap1, norm=norm1,
c=magnitude, facecolor='none',
marker='x', s=4, linewidths=0.8)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.