带有彩色面孔的 aplpy show_polygons()
aplpy show_polygons() with colorised faces
我有一些多边形,我想用 APLpy 在右 Ascension/Declination space 中绘制,多边形由另一个一维列表着色,但我无法得到 show_polygons()
工作。
我试图改编 APLpy show markers normalized by a colormap 的答案,但是当我 运行 它时,show_polygons()
不理解 kwargs cmap
, norm
,或 c
与 show_markers()
相同。
我改编的独立脚本:
import aplpy, numpy
from numpy import array
import matplotlib.pyplot as plt
from matplotlib import cm, colors
polygons = [array([[ 46.33681474, 34.75536787],
[ 45.04752709, 35.37650737],
[ 44.63035494, 34.73768723],
[ 46.33681474, 34.75536787]]), array([[ 46.45913142, 34.69050337],
[ 45.04717721, 35.37189917],
[ 44.6205633 , 34.72362768],
[ 46.45913142, 34.69050337]]), array([[ 46.52741447, 34.64997822],
[ 45.04457814, 35.36619781],
[ 44.60486296, 34.70107236],
[ 46.52741447, 34.64997822]])]
zvalues = [ 1.02018589e-10, 9.38471764e-12, 2.15806865e-11]
cmap1 = cm.YlOrBr
norm1 = colors.Normalize( numpy.min(zvalues), numpy.max(zvalues) )
fig = aplpy.FITSFigure( numpy.zeros( (10,10) ) )
fig.show_polygons( polygons, cmap=cmap1, norm=norm1, c=zvalues, facecolor='none' )
plt.save( fname='plot.png' )
运行 这会导致 show_polygons()
引发不同的 AttributeErrors:
AttributeError: Unknown property cmap
AttributeError: Unknown property norm
AttributeError: Unknown property c
我的版本:
$ python --version
Python 3.5.1 :: Continuum Analytics, Inc.
$ python
>>> import matplotlib
>>> print(matplotlib.__version__)
1.5.1
>>> import aplpy
>>> print(aplpy.__version__)
1.1.1
如何让 show_polygons()
工作?
首先,您尝试绘制的多边形坐标与您正在绘制的像素阵列不匹配 - 尽管我认为这对于您正在绘制的真实拟合图形来说不是问题。所以你应该把你的代码改成这样:
# fixed so that the polygons fall inside the image
fig = aplpy.FITSFigure(numpy.zeros((50,50)))
# zoom in on the coord values of the polygons
fig.recenter(45.5, 35, 1.5)
现在,实际回答这个问题:aplpy.FITSFigure
的不同方法将关键字参数传递给不同的 matplotib
例程 - 所以你不应该期望 show_polygons
和 show_markers
以同样的方式行事。事实上,他们的文档字符串声明 show_poligons
将其 kwargs
传递给 PatchCollection
class,而 show_markers
会将它们发送给 plt.scatter
。这就是属性错误不断发生的原因。
那么,如何通过一维颜色列表给色块上色呢?据我所知,没有 one-liner 解决方案,但您可以遍历多边形并分别为它们着色:
for p, c in zip(polygons, zvalues):
fig.show_polygons([p], facecolor=cmap1(norm1(c)),
edgecolor='none', alpha=0.3)
plt.show()
为我生成下图:
我有一些多边形,我想用 APLpy 在右 Ascension/Declination space 中绘制,多边形由另一个一维列表着色,但我无法得到 show_polygons()
工作。
我试图改编 APLpy show markers normalized by a colormap 的答案,但是当我 运行 它时,show_polygons()
不理解 kwargs cmap
, norm
,或 c
与 show_markers()
相同。
我改编的独立脚本:
import aplpy, numpy
from numpy import array
import matplotlib.pyplot as plt
from matplotlib import cm, colors
polygons = [array([[ 46.33681474, 34.75536787],
[ 45.04752709, 35.37650737],
[ 44.63035494, 34.73768723],
[ 46.33681474, 34.75536787]]), array([[ 46.45913142, 34.69050337],
[ 45.04717721, 35.37189917],
[ 44.6205633 , 34.72362768],
[ 46.45913142, 34.69050337]]), array([[ 46.52741447, 34.64997822],
[ 45.04457814, 35.36619781],
[ 44.60486296, 34.70107236],
[ 46.52741447, 34.64997822]])]
zvalues = [ 1.02018589e-10, 9.38471764e-12, 2.15806865e-11]
cmap1 = cm.YlOrBr
norm1 = colors.Normalize( numpy.min(zvalues), numpy.max(zvalues) )
fig = aplpy.FITSFigure( numpy.zeros( (10,10) ) )
fig.show_polygons( polygons, cmap=cmap1, norm=norm1, c=zvalues, facecolor='none' )
plt.save( fname='plot.png' )
运行 这会导致 show_polygons()
引发不同的 AttributeErrors:
AttributeError: Unknown property cmap
AttributeError: Unknown property norm
AttributeError: Unknown property c
我的版本:
$ python --version
Python 3.5.1 :: Continuum Analytics, Inc.
$ python
>>> import matplotlib
>>> print(matplotlib.__version__)
1.5.1
>>> import aplpy
>>> print(aplpy.__version__)
1.1.1
如何让 show_polygons()
工作?
首先,您尝试绘制的多边形坐标与您正在绘制的像素阵列不匹配 - 尽管我认为这对于您正在绘制的真实拟合图形来说不是问题。所以你应该把你的代码改成这样:
# fixed so that the polygons fall inside the image
fig = aplpy.FITSFigure(numpy.zeros((50,50)))
# zoom in on the coord values of the polygons
fig.recenter(45.5, 35, 1.5)
现在,实际回答这个问题:aplpy.FITSFigure
的不同方法将关键字参数传递给不同的 matplotib
例程 - 所以你不应该期望 show_polygons
和 show_markers
以同样的方式行事。事实上,他们的文档字符串声明 show_poligons
将其 kwargs
传递给 PatchCollection
class,而 show_markers
会将它们发送给 plt.scatter
。这就是属性错误不断发生的原因。
那么,如何通过一维颜色列表给色块上色呢?据我所知,没有 one-liner 解决方案,但您可以遍历多边形并分别为它们着色:
for p, c in zip(polygons, zvalues):
fig.show_polygons([p], facecolor=cmap1(norm1(c)),
edgecolor='none', alpha=0.3)
plt.show()
为我生成下图: