astropy常用命令 python天文绘图

绘图(结合mpl)

  1. 画出图像及contour
from astropy.wcs import WCS
from astropy.io import fits
import matplotlib.pyplot as plt

hdu=fits.open(filename)[0]
wcs=WCS(hdu.header)

ax=plt.subplot(projection=wcs)

#show image
ax.imshow(hdu.data, vmin=, vmax=, origin='lower')
'''or maybe np.log10(hdu[0].data)'''
#show contour
ax.contour(hdu.data, levels=[], colors='white', alpha=0.5)
  1. 添加标记及其他文件的坐标转换
    参考官网链接 Making plots with world coordinates
#添加其他坐标系的contour
ax.contour(othercoord.data, transform=ax.get_transform(WCS(othercoord.header)),\
	levels=, colors='white')
#添加方框
from matplotlib.patches import Rectangle
r = Rectangle((x_center., y_center.),.,., edgecolor='white', facecolor='none')
ax.add_patch(r)
	#shili
table_len=table['x'].shape[0]
for i in range(table_len):
    r = Rectangle((table['x'][i]-table['r'][i]/2,table['y'][i]-table['r2'][i]/2), table['r'][i],table['r2'][i], edgecolor='white', facecolor='none')
    ax.add_patch(r)
#绘制多边形
pgon = plt.Polygon(([0.15,0.15], [0.35, 0.4], [0.2, 0.6], [0.3, 0.2]))

#添加标记等见上述链接
  1. 调整显示, 增加图例, 添加第二坐标轴等次要步骤

添加第二坐标轴参考官网链接
Make a plot with both redshift and universe age axes using astropy.cosmology
Plots with different scales

#调整显示
建议在imshow时即使用 np.log10(hdu[0].data)

#增加图例(用"label")
plt.plot(x,y,label="my little line")
plt.legend(fontsize=10.)

#调整色彩
imshow中参数 cmap
最清晰但过于明亮: 'jet'
高级灰但略不明显: 'viridis'
  1. 坐标轴及label
    坐标轴相关 CoordinateHelper
#调整坐标轴格式
ax.coords[0].set_major_formatter('d.dd')
ax.coords[1].set_major_formatter('d.dd')
#在label中正确使用\rm
plt.xlabel(r'$Italic,{\rm Normal}$')
  1. 保存
plt.savefig('xxx.pdf',bbox_inches='tight')

Others:
https://matplotlib.org/faq/howto_faq.html

#自动选合适的bar_label颜色
text_color = 'white' if r * g * b < 0.5 else 'darkgrey'
  • 5
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python常用命令包括以下几个: 1. 要查看您正在运行的Python版本,可以使用以下命令: - python -? [1] - python -h [1] 2. 要查看Python版本号,可以使用以下命令: - python -V [2] - python --version [2] 3. 如果您想在不打开和编辑.py文件的情况下运行Python代码,可以使用以下命令: - python filename.py:直接运行指定的.py文件 4. 在命令行中执行Python代码时,您可能需要了解一些常用的命令: - print("Hello, World!"):打印输出文本或变量的值 - input("Enter your name: "):接收用户输入的数据 - if condition: ... else: ...:条件语句,根据条件执行不同的代码块 - for item in iterable: ...:循环语句,遍历可迭代对象并执行相应代码 - def function_name(parameters): ...:定义函数,用于封装可重用的代码块 - import module_name:导入外部模块,使用其中的函数和变量 - from module_name import function_name:从外部模块导入指定函数 - exit():退出Python解释器 Python是一种非常容易学习的编程语言,只要掌握了基本的语法和常用命令,就能够编写简单的程序。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [全网最全的Python常见命令大全,建议收藏,以防备用](https://blog.csdn.net/SpringJavaMyBatis/article/details/127451276)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值