Surface Plot xlim和ylim不限制数据

时间:2019-10-02 11:36:05

标签: matplotlib surface

我正在使用以下代码绘制3d曲面。但是xlim似乎不起作用,因为它只能限制轴,而不能限制数据本身。

import numpy as np
import matplotlib.pylab as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.colors as colors
import matplotlib.cm as cm
from mpl_toolkits import mplot3d
from mpl_toolkits.mplot3d import Axes3D
import os
xlim= (1, 60)
ylim=(300, 600)
Filenames = []
directory= "C:/Users/dipankas/OneDrive - Universitetet i Oslo/NAMM/Neutrons/Mn60Ni40As/HT"
for root, dirs, files in os.walk(directory):
for file in files:
       if file.endswith('.dat'):
       Filenames.append(file)
data=[]

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

Temperature=[]
for j in Filenames:
    Temperature.append(np.genfromtxt(j, dtype='float', skip_header=11, skip_footer=13, usecols=(1) ))
Temp=np.array(Temperature)


# slicing to isolate x y z for meshgrid
x= np.array(d[0,:,0]) 
y= Temp[:,0]
X,Y = np.meshgrid(x, y) 
Z = d[:,:,1] 

#######################################Ploting################

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax = plt.gca()
ax.plot_surface(X, Y, Z, cmap='summer', rstride=1, cstride=1, alpha=1)
ax.set_xlim(xlim)
ax.set_ylim(ylim)
ax.set_autoscale_on(False)
ax.set_xlabel('$2\/theta (^o)$', fontsize = 20)
ax.set_ylabel('$Temperature\/(k)$', fontsize=20)
ax.set_zlabel(r'$Intensity$', fontsize=20)
plt.tight_layout()
plt.show()
#######################################################

它生成此图像 [在此处输入图片说明]   [1]:https://i.stack.imgur.com/4UWna.jpg
关于如何使3D图形平滑,我还有另一个问题?
请提出建议。

谢谢
Dipankar

0 个答案:

没有答案