Becksteinlab / GromacsWrapper

GromacsWrapper wraps system calls to GROMACS tools into thin Python classes (GROMACS 4.6.5 - 2024 supported).
https://gromacswrapper.readthedocs.org
GNU General Public License v3.0
169 stars 53 forks source link

Legend and title are not shown #242

Closed pacho2 closed 1 year ago

pacho2 commented 1 year ago

Hello,

I am trying to use GromacsWrapper to see attached file (generated by gromacs mindist tool).

I am doing the following (on a plain "python3" session run from the terminal)

>>> import matplotlib.pyplot as plt
>>> xvg=gromacs.formats.XVG(filename="CB_to_P_2.xvg")
>>> print(xvg.array) -> to try to avoid the "lazy loading issue mentioned at https://github.com/Becksteinlab/GromacsWrapper/issues/13#issuecomment-1137771811
[[0.000000e+00 5.000000e-02 1.000000e-01 ... 4.999000e+02 4.999500e+02
  5.000000e+02]
 [6.871651e-01 7.082978e-01 7.039531e-01 ... 7.500433e-01 6.888657e-01
  7.289565e-01]]
>>> print(xvg.names)
['P-r_2_&_CB']
>>> print(xvg.metadata)
{'legend': ['on', 'box on', 'loctype view', '0.78, 0.8', 'length 2']}
>>> plt.show()
>>> xvg.plot()
/usr/lib/python3.11/site-packages/numpy/core/fromnumeric.py:3464: RuntimeWarning: Mean of empty slice.
  return _methods._mean(a, axis=axis, dtype=dtype,
/usr/lib/python3.11/site-packages/numpy/core/_methods.py:192: RuntimeWarning: invalid value encountered in scalar divide
  ret = ret.dtype.type(ret / rcount)
/usr/lib/python3.11/site-packages/gromacs/fileformats/xvg.py:1085: AutoCorrectionWarning: Plot had 10001 datapoints > maxpoints = 10000; decimated to 10000 regularly spaced points from the histogrammed data with mean_histogrammed_function().
  warnings.warn("Plot had %d datapoints > maxpoints = %d; decimated to %d regularly "
<Axes: >
>>> plt.show()

But the opened matplot lib window keeps missing Title and Legend information :-/

Thanks for your help

pacho2 commented 1 year ago

CB_to_P_2.xvg.txt

pacho2 commented 1 year ago

image

Screenshot showing xmgrace at left and matplotlib at right... also some lines are broken in the plot... but that is a different issue I guess :/

orbeckst commented 1 year ago

The XVG class does not use the legend from the file for plotting, sorry. The XVG.plot() function is rather simple. You'll have to use normal matplotlib functions to add your own legends.

pacho2 commented 1 year ago

OK, thanks for the info