mailRe: Development document for adding support for matplotlib graphing to relax.


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by Edward d'Auvergne on March 27, 2014 - 11:54:
Hi,

This all works!  To have this, we can add the 'format' argument to the
matplotlib.write user function.  It can have the following values
which can all be documented in the docstring:

- 'Script', this produces a single Python script containing everything
- all the data and matplotlib commands needed, and has a single show()
call at the end,
- 'PDF',
- 'PS',
- 'EPS',
- 'PNG',
- 'SVG'.

Then the matplotlib.view user function could have the 'file',
'interpreter', and 'python_exe' options.  If the file is one of the
vector or bitmap graphics, then the OS dependent image viewer can be
opened.  But if it is the Python script, then 'interpreter' argument
can be used.  It could have two values 'internal' and 'external'.
'internal' will just run plt.show() in the current relax instance,
i.e. the matplotlib script will be imported as a module.  'external'
would then take the 'python_exe' argument value and run the matplotlib
script in any Python version the user chooses.  I think this would
enable everything you mention.

Regards,

Edward


On 27 March 2014 11:30, Troels Emtekær Linnet <tlinnet@xxxxxxxxx> wrote:
Hi Edward.

Regarding #3.
I think the best support would be make an external python file.

The question is, if the data should be store in different variable arrays,
containing x,y data etc.
or as a ordered dictionary.

The matplotlib.view(), should then just call: "python spin_file.py".
Then relax is not dependent on matplotlib installation, but a functional
external python installation with matplotlib.
Here "python" could point to for example to the python packaged in the
Enthought distribution.
That distribution is bundled with matplotlib. But it could be any of these
easy python distributions.

That should save a default .png file, but a plt.show() in the script will
call the graph window to appear, and the graph can me modified by hand and
saved as wished.

For this method, relax don't need a module check.
(There is also no module check for xmgrace ? )

Again about the data.
If the relax state files are simple xml files, then the relax could instead
write a special matplotlib state file with the interpolated values saved.
And the plot script would access this state, extract x,y values and plot
them?

Just some thoughts.

Troels Emtekær Linnet

Ah, there is one step I forgot about.  The Grace graph generation
happens in lib.software.grace module whereas the assembly of data from
the relax data pipe happens in the pipe_control.grace module.
Therefore the missing step is:


6)  Matplotlib interface.

Create a new module lib.software.matplotlib.  This is where matplotlib
is imported and the plots are produced and saved.  The
lib.software.grace module should not be copied as the functions in
lib.software.matplotlib would be completely different.  But the
write_xy_data() and write_xy_header() functions can be used as
inspiration. As matplotlib does not appear to have a header from data
separation, then maybe on write_xy() function can be written for 2D xy
data plots.  A different function for 3D data could be created as
maybe write_3D().


Note that at some point in the future, the plotting modules in
lib.software might shift to lib.plotting.

Regards,

Edward


On 27 March 2014 10:28, Edward d'Auvergne <edward@xxxxxxxxxxxxx> wrote:
Hi,

The following is planning document for adding support for matplotlib
graphing to relax.  The plan will be broken into a few simple steps:

1)  Module detection.

Firstly the dep_check module would need to be modified to detect the
presence of the matplotlib Python package.  In addition, the
package_info() method in the 'info' module should be changed to print
out if matplotlib is present and which version is present
(matplotlib.__version__).  Then matplotlib will be shown when running
relax with the --info command line option.


2)  Icons

For the GUI and the user manual, icons are needed.  These can be taken
from the matlplotlib sources and added to the graphics/relax_icons/
directories.  The 16x16, 24x24, 32x32, and 48x48 icons could be taken
from the ./doc/_static/favicon.ico file, specifically layers #4, #5,
and #6.  The 128x128 icon used in the manual could be regenerated
using the matplotlib graphic script ./examples/api/logo2.py, but with
the text removed.


3)  Uf frontend.

For this, the user_functions.grace module can be copied and modified
to change all instances of 'grace' with 'matplotlib'.  So the user
functions would be matplotlib.view and matplotlib.write.  New user
functions could be added later on if additional functionality from
matplotlib is desired.


4)  Uf backend.

The pipe_control.grace module can be copied to pipe_control.matplotlib
and changed as needed.  The key functions are view() and write() as
these are used by the user function frontends.  All other functions
can be added as needed to simplify the matplotlib graph generation
(and the old ones form grace deleted).


5)  Saving format.

Do we output in SVG or PNG?  I don't know matplotlib, but is there a
way of saving a matplotlib native file format so it can be modified
later?  The options should be available as arguments to the
matplotlib.write user function.


Completion of these steps is sufficient for full matplotlib support
within relax.  Then adding the plotting as default for the
auto-analyses would be trivial.

Regards,

Edward

_______________________________________________
relax (http://www.nmr-relax.com)

This is the relax-devel mailing list
relax-devel@xxxxxxx

To unsubscribe from this list, get a password
reminder, or change your subscription options,
visit the list information page at
https://mail.gna.org/listinfo/relax-devel



Related Messages


Powered by MHonArc, Updated Fri Mar 28 04:20:13 2014