APLpy显示由颜色图归一化的标记 [英] APLpy show markers normalized by a colormap

查看:123
本文介绍了APLpy显示由颜色图归一化的标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用APLpy绘制拟合文件,并希望以一定的ra,dec值在该拟合文件上过度绘制标记.我希望标记的颜色用另一个参数编码,可以说是一个幅度.

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.

所以我要做的是从文本文件(positions.dat)中读取标记坐标和相应的幅度:

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)                                                           

我在position.dat文件中的大小都在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

positions.dat文件如下所示:

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

推荐答案

问题是matplotlib的散布不能采用edgecolorfacecolor的值,这些值不是颜色数组(即RGB值的数组) .实现您要尝试执行的操作的正确方法是使用散点图的c参数,因此在这种情况下:

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)

这篇关于APLpy显示由颜色图归一化的标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆