首页 > 解决方案 > 在 imshow 中绘图未正确采用 x 值

问题描述

我有以下二维绘图代码。我从文件中读取数据并附加它们。在我将它们转换为数组之后。它绘制但没有正确采用 theta_min 和 theta_mix。作为 x 值,它仅采用所需值的位置,而不采用值本身。请建议。

谢谢你的帮助。 这是我得到的输出

import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable

Filename='DS_MNASP_12_RT-483K_'  
FileExtension= '.dat' 
FileNumberBegin =1 
FileNumberEnd =10 
theta_min=1
theta_max=10
RT = 290 
HT=523 


Filenames = []
    for i  in range(FileNumberBegin,FileNumberEnd + 1):
    Filenames.append(Filename + (4-len(str(i)))*'0' + str(i) + 'p' + 
                 FileExtension)

data=[]
for j in Filenames:
    data.append(np.genfromtxt(j, dtype='float', skip_header=41)) 
d=np.array(data)

ylabel = '$Temperature\/(k)$'
xlabel = '$2\/theta (degrees)$'



x = d[0,theta_min:theta_max,0] 
y = (np.arange(RT,HT+1, dtype='float64'))
z = d[:,theta_min:theta_max,1] 

X,Y = plt.meshgrid(x, y) 
Z = z 


xmin = theta_min
xmax = theta_max


im = plt.imshow(Z, origin='lower', aspect='auto', extent=[xmin, xmax, y[0], 
    y[-1]]) 

ax = plt.gca()
ax.set_autoscale_on(False)
ax.set_xlabel(xlabel, fontsize = 30)
ax.set_ylabel(ylabel, fontsize = 30)
ax.tick_params(labelsize=20, pad =7, direction='out', width=2, top='off', 
right='off')
plt.tight_layout()
plt.show()

标签: matplotlibimshow

解决方案


推荐阅读