Reputation: 233
I got a .fig file generated in Matlab and I would like to display it in python environment, or at least retrieve the data. It works well when the original figure does not contain error bars. But when I have error bars then it looks like a staircase. Any ideas on how I could fix it?
The code I have been using is this:
## 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],linestyle=linestyle,linewidth=3.0)
counter=2
else:
x = line.properties.XData
y = line.properties.YData
plt.plot(x[y>0],y[y>0],linestyle=linestyle,linewidth=4.0,color=[r,g,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',dpi=300)#,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^{2}$',r'$10^{4}$']
x = [1e-2,1e-1,1e0,1e1,1e2,1e3]
plt.tick_params(axis='x',labelsize=size_f)
plt.tick_params(axis='y',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', format='png',dpi=300,bbox_inches='tight')
plt.savefig(r'C:\Users\nikos.000\vlahos\eps\escape_distr_prot.eps', format='eps',dpi=300,bbox_inches='tight')
show()
return
plotFig(r'C:\Users\nikos.000\neutrons\f5b P=1.fig',fignr=1)
This is how the figure looks:
The original .fig file can be found here:
https://www.dropbox.com/sh/iddxpfvxz85abci/AAAU9p0DM5OYtpI7mE-nLAuga?dl=0
Upvotes: 1
Views: 182