【问题标题】:APLpy show markers normalized by a colormapAPLpy 显示由颜色图标准化的标记
【发布时间】:2014-09-17 23:56:15
【问题描述】:

我正在使用 APLpy 绘制拟合文件,并希望在该拟合文件上以某些 ra,dec 值重叠标记。我想用另一个参数对标记的颜色进行编码,比如说一个量级。

所以我要做的是从文本文件(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))                                   

我定义了一个颜色图及其规范化:

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

我在positions.dat文件中的大小都在10到20之间来测试代码。

我尝试如下绘制标记:

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

当我这样做时,我总是得到错误:

ValueError: Color array must be two-dimensional

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

【问题讨论】:

标签: python matplotlib aplpy


【解决方案1】:

问题在于 matplotlib 的 scatter 不能为 edgecolorfacecolor 获取不是颜色数组(即 RGB 值数组)的值。实现你想要做的事情的正确方法是使用 scatter 的 c 参数,所以在这种情况下:

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

【讨论】:

    猜你喜欢
    • 2012-07-22
    • 2011-02-12
    • 2012-11-29
    • 2019-03-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    相关资源
    最近更新 更多