tgdane / pygix

A python library for reduction of 2-dimensional grazing-incidence and fibre diffraction data
MIT License
6 stars 18 forks source link

pgyix plotting #7

Open ttortorici opened 3 months ago

ttortorici commented 3 months ago

Hi,

I get the following issue when importing the plotting tool from pygix using from pygix import plotting as ppl


ValueError Traceback (most recent call last) Cell In[1], line 3 1 import pygix 2 import fabio ----> 3 from pygix import plotting as ppl

File c:\Users--\anaconda3\envs\xrd\Lib\site-packages\pygix\plotting.py:46 39 mpl.rc('text', usetex=True) 41 latexpre = [r'\usepackage{siunitx}', 42 r'\sisetup{detect-all}', 43 r'\usepackage{helvet}', 44 r'\usepackage[EULERGREEK]{sansmath}', 45 r'\sansmath'] ---> 46 mpl.rcParams['text.latex.preamble'] = latexpre 48 DEFAULT_UNIT = 'nm^-1' 49 LABELS_DICT = { 50 'raw': ['y (pixels)', 'x (pixels)'], 51 'angular': ['2theta_f (deg)', 'alpha_f (deg)'], (...) 56 'qz': ['q_z (nm^-1)', 'Intensity (a.u.)'], 57 'qxy': ['q_xy (nm^-1)', 'Intensity (a.u.)']}

File c:\Users--\anaconda3\envs\xrd\Lib\site-packages\matplotlib__init.py:734, in RcParams.setitem(self, key, val) [732](file:///C:/Users/--/anaconda3/envs/xrd/Lib/site-packages/matplotlib/init.py:732) cval = self.validatekey [733](file:///C:/Users/--/anaconda3/envs/xrd/Lib/site-packages/matplotlib/init.py:733) except ValueError as ve: --> [734](file:///C:/Users/--/anaconda3/envs/xrd/Lib/site-packages/matplotlib/init.py:734) raise ValueError(f"Key {key}: {ve}") from None [735](file:///C:/Users/--/anaconda3/envs/xrd/Lib/site-packages/matplotlib/init__.py:735) self._set(key, cval) 736 except KeyError as err:

ValueError: Key text.latex.preamble: Could not convert ['\usepackage{siunitx}', '\sisetup{detect-all}', '\usepackage{helvet}', '\usepackage[EULERGREEK]{sansmath}', '\sansmath'] to str

HarlanHeilman commented 2 months ago

I have the same issue. It was partially solved by editing the source code such that

...
latexpre = [r'\usepackage{siunitx}',
            r'\sisetup{detect-all}',
            r'\usepackage{helvet}',
            r'\usepackage[EULERGREEK]{sansmath}',
            r'\sansmath']
...

is replaced with a single long string

latexpre = r'\usepackage{siunitx} \sisetup{detect-all} \usepackage{helvet} \usepackage[EULERGREEK]{sansmath} \sansmath'

though you could similarly just splice the list into a single string. Though immediately after solving this issue you will run into another one depending on the version of matplotlib you have installed. Since the method (Axis.set_axis_bgcolor())[https://matplotlib.org/2.1.2/api/_as_gen/matplotlib.axes.Axes.set_axis_bgcolor.html] has been depreciated since version 2.0.

File .venv\Lib\site-packages\pygix\plotting.py:385, in implot(data, x, y, mode, xlim, ylim, xlabel, ylabel, cmap, clim, colorbar, newfig, show, tight_layout, filename, **kwargs)
    [382](.venv/Lib/site-packages/pygix/plotting.py:382)     cax = divider.append_axes("right", size="5%", pad=0.05)
    [383](.venv/Lib/site-packages/pygix/plotting.py:383)     plt.colorbar(im, cax=cax)
--> [385](.venv/Lib/site-packages/pygix/plotting.py:385)     ax.set_axis_bgcolor(colormap(0))
    [387](.venv/Lib/site-packages/pygix/plotting.py:387)     if tight_layout:
    [388](.venv/Lib/site-packages/pygix/plotting.py:388)     plt.tight_layout()