如何解决在python中加载.fig图形表单Matlab误差线使图形看起来很奇怪
我在 Matlab 中生成了一个 .fig 文件,我想在 python 环境中显示它,或者至少检索数据。当原始图形不包含误差线时,它运行良好。但是当我有误差条时,它看起来像一个楼梯。关于如何修复它的任何想法?
我一直使用的代码是这样的:
## escape disti time for ions ##
size_f =26
def plotfig(filename,fignr=1):
from scipy.io import loadmat
from numpy import size
from matplotlib.pyplot import plot,figure,xlabel,ylabel,show,clf,xlim,ylim,legend,yticks,xticks
d = loadmat(filename,squeeze_me=True,struct_as_record=False)
ax1 = d['hgS_070000'].children
if size(ax1) > 1:
legs= ax1[1]
ax1 = ax1[0]
else:
legs=0
figure(fignr)
clf()
#hold(True)
counter = 0
counter1 =0
# x=np.zeros((1000,1000))
#y=np.zeros((1000,1000))
for line in ax1.children:
if line.type == 'graph2d.lineseries':
if hasattr(line.properties,'Marker'):
mark = "%s" % line.properties.Marker
mark = mark[0]
else:
mark = '.'
if hasattr(line.properties,'Linestyle'):
linestyle = "%s" % line.properties.Linestyle
else:
linestyle = '-'
if hasattr(line.properties,'Color'):
r,g,b = line.properties.Color
else:
r = 0
g = 0
b = 1
if hasattr(line.properties,'MarkerSize'):
marker_size = line.properties.MarkerSize
else:
marker_size = 1
#if counter1 ==0:
x = line.properties.XData
y = line.properties.YData
#counter1=1
#else:
# x1 = line.properties.XData
# y1 = line.properties.YData
if counter ==0:
x = line.properties.XData
y = line.properties.YData
plt.plot(x[y>0],y[y>0],linestyle=linestyle,linewidth=3.0)
counter=1
elif counter==1:
x1 = line.properties.XData
y1 = line.properties.YData
#plt.plot(x1[y1>0],y1[y1>0],linewidth=3.0)
counter=2
else:
x = line.properties.XData
y = line.properties.YData
plt.plot(x[y>0],linewidth=4.0,color=[r,b])
plt.yscale('log')
plt.xscale('log')
elif line.type == 'text':
if counter < 1:
xlabel(r'$%s$' % line.properties.String,fontsize =18)
#xlabel('%s' % line.properties.String,fontsize = 18)
counter += 1
elif counter < 2:
ylabel(r'$%s$' % line.properties.String,fontsize = 18)
# ylabel('%s' % line.properties.String,fontsize = 18)
counter += 1
ylim(1e-7,1e-1)
#ylim(ax1.properties.YLim)
xlim((1e-2,1e3))
plt.rcParams["figure.figsize"] = [10,8]
plt.tick_params(axis='x',labelsize=size_f)
plt.tick_params(axis='y',labelsize=size_f)
plt.ylabel(r'$p(t_{esc})$',fontsize=size_f)
plt.xlabel(r'$t_{esc} \ [sec]$',fontsize=size_f)
#plt.savefig(r'C:\Users\nikos.000\vlahos\png\escape distr_elec.png',format='png',dpi=300)#,bBox_inches='tight')
#plt.savefig(r'C:\Users\nikos.000\vlahos\eps\escape_distr_elec.eps',format='eps',bBox_inches='tight')
#### Set tick size ####
labels = [r'$10^{-2}$',r'$10^{-1}$',r'$10^{0}$',r'$10^{1}$',r'$10^{2}$',r'$10^{3}$']#,r'$10^{4}$']
x = [1e-2,1e-1,1e0,1e1,1e2,1e3]
plt.tick_params(axis='x',labelsize=size_f)
plt.xticks(x,labels)
labels1 = [r'$10^{-6}$',r'$10^{-4}$',r'$10^{-2}$']
y = [1e-6,1e-4,1e-2,]
plt.yticks(y,labels1)
if legs:
leg_entries = tuple(legs.properties.String)
py_locs = ['upper center','lower center','right','left','upper right','upper left','lower right','lower left','best']
MAT_locs=['north','south','east','west','northeast','northwest','southeast','southwest','best']
Mat2py = dict(zip(MAT_locs,py_locs))
location = legs.properties.Location
leg1=legend(leg_entries,loc=Mat2py[location],frameon=False,fontsize=size_f)
leg1.legendHandles[1].set_color('black')
#plt.xticks(fontsize=18 )
#plt.yticks(fontsize=18)
#### Save figure ####
plt.savefig(r'C:\Users\nikos.000\vlahos\png\escape distr_prot.png',dpi=300,bBox_inches='tight')
plt.savefig(r'C:\Users\nikos.000\vlahos\eps\escape_distr_prot.eps',bBox_inches='tight')
show()
return
plotfig(r'C:\Users\nikos.000\neutrons\f5b P=1.fig',fignr=1)
这个图是这样的:
https://www.dropbox.com/sh/iddxpfvxz85abci/AAAU9p0DM5OYtpI7mE-nLAuga?dl=0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。