2017-09-26 148 views
0

我有绘出针对经度点的磁通密度的曲线图:标签x轴

enter image description here

但我需要x轴从24.3读 - > 0在中心 - > 335.7

我已经使用matplotlib.ticker设置每30个像素的滴答,相当于每1度。

import numpy as np 
from astropy.io import fits 
import matplotlib.pyplot as plt 
import matplotlib.ticker as ticker 

hdulist = fits.open('w1_subtracted_2_deg.fits') 
nodisk_data, nodisk_header = hdulist[0].data, hdulist[0].header 

x = range(nodisk_data.shape[1]) 
y = np.sum(nodisk_data, axis = 0) 

ax = plt.axes() 
ax.xaxis.set_major_locator(ticker.MultipleLocator(300)) 
ax.xaxis.set_minor_locator(ticker.MultipleLocator(30)) 

plt.plot(x, y) 
plt.title('Longitudinal sum of flux density per steradian') 
plt.xlabel(r'Galactic longitude, $\ell$') 
plt.ylabel(r'Integrated flux density per steradian, $MJ.sr^{-1}$') 
plt.grid(True) 
plt.show() 
plt.savefig('add_cols.png') 

hdulist.close() 

有一个简单的命令,我可以用这一点,也许在axes类,或是否需要进行硬编码的x轴点的列表?或者,也可以将中心像素设置为参考像素,并在圆周的任一方向上绘制标记为24.3度的图?

+2

我会通过首先改变沿x轴的_values_到正确度,然后绘制度值并让蜱是做到这一点自动。 – cphlewis

回答

0

我固定x轴标签这样的:

xticks = [0, 183, 365, 547, 729, 912, 1095, 1277, 1459] 
long_marks = [24, 18, 12, 6, 0, 354, 348, 342, 335] 
ax = plt.axes() 
ax.set_xticks(xticks) 
ax.set_xticklabels(long_marks)