jacopo-chevallard / PyP-BEAGLE

4 stars 1 forks source link

latex - python incompatibility #8

Closed ahwofford closed 8 years ago

ahwofford commented 8 years ago

My python version is: Python 2.7.11 :: Anaconda 4.0.0 (x86_64)

I am having trouble with latex and pyp-beagle. Do I need a special package? For instance, if in the .json file I use:

"tauv_eff": { "range": [0.001, 5.0], "label": "$\log \hat{\tau}_V$", "log" : true },

I get:

$$\log \hat{\tau}_\V$$ ^ Expected end of text (at char 0), (line:1, col:1)

AlbaVidal commented 8 years ago

I have the same versions and the same error. And whereas Aida gets the pdf of the triangle plot, I don't.

AlbaVidal commented 8 years ago

@eclake This is the error I get when trying to run pypbeagle in my laptop:

bash-4.3$ Python test_spectra.py -r /Users/alba/Documents/Documentos_Mac/ascii_tofits/results/COS -p /Users/alba/Documents/Documentos_Mac/ascii_tofits/param/test_aida_spectra1p0.param
/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.py:508: UserWarning: matplotlibrc text.usetex can not be used unless ghostscript-7.07 or later is installed on your system
  'installed on your system') % gs_req)
/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
param_file:  /Users/alba/Documents/Documentos_Mac/ascii_tofits/param/test_aida_spectra1p0.param
ID:  hst_13788_beagle_sbs0335_dx1.0
WARNING:root:The plot "hst_13788_beagle_sbs0335_dx1.0_BEAGLE_marginal_SED_spec.pdf" already exists. 
 Exiting the function.
Traceback (most recent call last):
  File "test_spectra.py", line 72, in <module>
    my_PDF.plot_triangle(ID)
  File "../PyP-BEAGLE/beagle_pdf.py", line 172, in plot_triangle
    g.triangle_plot(samples, filled=True, line_args=line_args)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 1897, in triangle_plot
    no_extra_legend_space=upper_roots is None)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/getdist/plots.py", line 1504, in finish_plot
    plt.tight_layout(h_pad=0, w_pad=0)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1379, in tight_layout
    fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/figure.py", line 1754, in tight_layout
    rect=rect)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/tight_layout.py", line 349, in get_tight_layout_figure
    pad=pad, h_pad=h_pad, w_pad=w_pad)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/tight_layout.py", line 126, in auto_adjust_subplotpars
    tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots])
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 3683, in get_tightbbox
    bb_yaxis = self.yaxis.get_tightbbox(renderer)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/axis.py", line 1086, in get_tightbbox
    bb.append(a.get_window_extent(renderer))
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/text.py", line 961, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/text.py", line 361, in _get_layout
    ismath=ismath)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 234, in get_text_width_height_descent
    self.mathtext_parser.parse(s, self.dpi, prop)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/mathtext.py", line 3120, in parse
    box = self._parser.parse(s, font_output, fontsize, dpi)
  File "/Users/alba/anaconda2/lib/python2.7/site-packages/matplotlib/mathtext.py", line 2374, in parse
    six.text_type(err)]))
ValueError: 
$ $
^
Expected end of text (at char 0), (line:1, col:1)

After the warnings, there is one that can ring the bell but that I have tried unsuccesfully to fix (matplotlibrc text.usetex can not be used unless ghostscript-7.07 or later is installed on your system)

I simplified my .json as much as I could and now it looks like:

{
"mass": {
  "range": [3.0, 9.0],
  "label": " sss"
},

"tauv_eff": {
  "range": [0.001, 5.0],
  "label": " ", 
  "log" : true
},

"max_stellar_age": {
  "range": [6.0, 10.0],
  "label": " "
},

"metallicity": {
  "range": [-2.2, 0.24],
  "label": " "
},

"sigma": {
  "range": [50.0, 500.0],
  "label": " "
},

"nebular_logU": {
  "range": [-4.0, -1.0],
  "label": " hi"
}

} 

Any comment that you have, if any, is more than welcome. Thanks a lot!

AlbaVidal commented 8 years ago

So I finally fixed this error. The error was that ghostscript-7.07 was not correctly installed. I used brew to install it and then link it. I found several permission errors that I fixed simply changing them with chmod. So now I can draw also triangle plots!

jacopo-chevallard commented 8 years ago

That's great, well done!!

If I remember well, @ahwofford had the same problem, so she may try the same solution. Maybe you can give some more details, step-by-step, on what you did, so that other people with the same problem can just follow your solution!

AlbaVidal commented 8 years ago

Sure, what I tried is:

brew install gs

Then, I had to link the library:

brew link gs

And here I had several permission problems saying that the folder xxx was not readable/accessible. I took all of them and changed the permissions by doing:

sudo chown -R `whoami` : admin xxx

Here also brew suggested me to rewrite the permissions so I did:

brew link --overwrite gs

And I think that's all I did. @ahwofford let me know if it also works for you.

jacopo-chevallard commented 8 years ago

:)

wudlike commented 4 years ago

I had the same problem and spent a lot of time to fix it. I tried to implement a python file which contains latex symbol like \alpha, \beta (i have tried to write as: label = '$\alpha$', label = r'$\alpha$', label = '\alpha'), but all of them do not work, and i got error ValueError: $$\alpha_s$$ ^ Expected end of text (at char 0), (line:1, col:1)

I finally fixed error by writing label as : '\alpha'. hope helpful to all of you