title: Display .fig Matlab file in python
body: <p>I got a <code>.fig</code> file generated in Matlab and I would like to display it in python environment, or at least retrieve the data.</p>
  <p>I see that another question (<a href="https://stackoverflow.com/questions/8172931/data-from-a-matlab-fig-file-using-python">this one</a>) has been asked on this subject, but I am not allowed to comment there because not enough reputation.</p>
  <p>In particular the user Sascha proposed the following script:</p>
  <pre><code>def plotFig(filename,fignr=1):
      from scipy.io import loadmat
      from numpy import size
      from matplotlib.pyplot import plot,figure,hold,xlabel,ylabel,show,clf,xlim,legend
      d = loadmat(filename,squeeze_me=True, struct_as_record=False)
      ax1 = d['hgS_070000'].children
      if size(ax1) &gt; 1:
          legs= ax1[1]
          ax1 = ax1[0]
      else:
          legs=0
      figure(fignr)
      clf()
      hold(True)
      counter = 0    
      for line in ax1.children:
          if line.type == 'graph2d.lineseries':
              if hasattr(line.properties,'Marker'):
                  mark = &quot;%s&quot; % line.properties.Marker
                  mark = mark[0]
              else:
                  mark = '.'
              if hasattr(line.properties,'LineStyle'):
                  linestyle = &quot;%s&quot; % 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                
              x = line.properties.XData
              y = line.properties.YData
              plot(x,y,marker=mark,linestyle=linestyle,color=color(r,g,b),markersize=marker_size)
          elif line.type == 'text':
              if counter &lt; 1:
                  xlabel(&quot;%s&quot; % line.properties.String,fontsize =16)
                  counter += 1
              elif counter &lt; 2:
                  ylabel(&quot;%s&quot; % line.properties.String,fontsize = 16)
                  counter += 1        
      xlim(ax1.properties.XLim)
      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
          legend(leg_entries,loc=Mat2py[location])
      hold(False)
      show()
  </code></pre>
  <p>There are several errors I get when I try to implement it in Spyder 4.1.5 (python 3.7.7), and they do not appear at the same time:</p>
  <ol>
  <li><p>The first error I get was <code>undefined name 'color'</code>. This error was solved by Ander Biguri in a comment here below. However as soon as this error was solved, another appeared.</p>
  </li>
  <li><p>The second error is <code>cannot import name 'hold' from 'matplotlib.pyplot'</code>: apparently the command <code>hold</code> has been deprecated since considered useless. I can avoid the error by commenting the lines of the code where this command appears. Then the following error appears</p>
  </li>
  <li><p><code>'mat_struct' object has no attribute 'String'</code></p>
  </li>
  </ol>
  <p>I have no idea how to solve this problem. The point is that I would like to have a functioning code.
  Can anyone help?</p>