xraypy / xraylarch

Larch: Applications and Python Library for Data Analysis of X-ray Absorption Spectroscopy (XAS, XANES, XAFS, EXAFS), X-ray Fluorescence (XRF) Spectroscopy and Imaging, and more.
https://xraypy.github.io/xraylarch
Other
133 stars 64 forks source link

Issue plotting the result when using DiffKK #416

Closed Ayrtonb1 closed 1 year ago

Ayrtonb1 commented 1 year ago

Hi there. In section 13.9 of the Larch Github manual, it refers to computing the f' and f" values as in Cross et al. (1998). I have managed to install the relevant modules and import the relevant libraries. However, I cannot work out how to plot the results. It is described in the example as:

''' newplot(dkk.energy, dkk.f2, label='f2', xlabel='Energy (eV)', ylabel='scattering factors', show_legend=True, legend_loc='lr') plot(dkk.energy, dkk.fpp, label='f"(E)') plot(dkk.energy, dkk.f1, label='f1') plot(dkk.energy, dkk.fp, label='f\'(E)') '''

However this does not work. I have tried matplotlib.pyplot and also wxmplot but neither work. I don't think the wxpython library is compatible with my Spyder IDE, as Python crashes whenever I try to use Wxpython to load this result. Does anybody have a solution?

newville commented 1 year ago

@Ayrtonb1 Yeah, the plotting functions from Larch use wxPython and the wxmplot library. That can probably run sort-of-OK but probably not very well in IPython or Jupyter. Spyder as an editor should be fine, but this plotting might not work well for code run in spyder's built-in IPython window using some IPython kernel.

I have not looked into details of making that work better, but would not be opposed to someone else doing that. I don't use IPython very often and rarely even install Spyder. But of course, you can you other plotting libraries if you want ;).

maurov commented 1 year ago

@Ayrtonb1 as said by @newville the plotting in the Larch shell assumes a Wx environment, which is not compatible with a Spyder IDE (Qt based). On the other hand, if you use Larch as a python library you can easily plot the arrays in the group with simple matplotlib or Plotly (you can refer to larch.plot.plotly_xafsplots module). This is all documented in the documentation or in the Jupyter examples, so I close the issue. If you need further help, feel free to re-open it.