[英]aplpy show_polygons() with colorised faces
I've got some polygons I'd like to plot in Right Ascension/Declination space with APLpy, with the polygons colored by another 1D list, but I can't get show_polygons()
to work. 我想用APLpy在Right Ascension / Declination空间中绘制一些多边形,这些多边形由另一个1D列表着色,但是我无法使show_polygons()
工作。
I tried to adapt the answer from APLpy show markers normalized by a colormap , but when I run it, show_polygons()
doesn't understand the kwargs cmap
, norm
, or c
the same way show_markers()
does. 我试着去适应从答案由颜色表归APLpy显示标记 ,但是当我运行它, show_polygons()
不理解kwargs cmap
, norm
,或c
以同样的方式show_markers()
一样。
My adapted, standalone script: 我改编的独立脚本:
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' )
Running this causes show_polygons()
to raise different AttributeErrors: 运行此命令会导致show_polygons()
引发不同的AttributeErrors:
AttributeError: Unknown property cmap
AttributeError: Unknown property norm
AttributeError: Unknown property c
My versions of things: 我的版本:
$ 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
How can I get show_polygons()
to work? 如何使show_polygons()
工作?
First off, the polygon coordinates you're trying to plot don't match with the pixel array you're plotting - although I assume that's not a problem for a real fits figure you're plotting. 首先,您要绘制的多边形坐标与您要绘制的像素阵列不匹配-尽管我认为这对您要绘制的真实拟合图来说不是问题。 So you should change your code to something like this instead: 因此,您应该将代码更改为如下所示:
# 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)
Now, actually answering the question: different methods of aplpy.FITSFigure
pass keyword arguments to different matplotib
routines - so you shouldn't expect show_polygons
and show_markers
to behave in the same way. 现在,实际回答这个问题:不同的aplpy.FITSFigure
方法将关键字参数传递给不同的matplotib
例程-因此,您不应该期望show_polygons
和show_markers
表现相同。 In fact, their docstrings state that show_poligons
passes its kwargs
to a PatchCollection
class, while show_markers
would send them along to plt.scatter
. 实际上,它们的文档字符串表明show_poligons
将其kwargs
传递给PatchCollection
类,而show_markers
会将它们发送给plt.scatter
。 That's why the attribute errors keep happening. 这就是为什么属性错误不断发生的原因。
So, how to color the patches by a 1d color list then? 那么,如何通过一维颜色列表为补丁着色呢? As far as I know, there's no one-liner solution, but you can loop over the polygons and color them individually: 据我所知,没有单线解决方案,但是您可以循环显示多边形并分别为其着色:
for p, c in zip(polygons, zvalues):
fig.show_polygons([p], facecolor=cmap1(norm1(c)),
edgecolor='none', alpha=0.3)
plt.show()
Which produces the following figure for me: 这为我产生了下图:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.