Skip to content

Commit

Permalink
beautify sphinx generated doc, re #10761
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeMPouzols committed Dec 11, 2014
1 parent cfc313a commit 832fe21
Showing 1 changed file with 83 additions and 23 deletions.
106 changes: 83 additions & 23 deletions Code/Mantid/MantidPlot/pymantidplot/future/pyplot.py
Expand Up @@ -15,6 +15,8 @@
To use this new functionality you first need to import the new pyplot module:
.. code-block:: python
from pymantidplot.future.pyplot import *
Please do not forget this step, otherwise you may get arcane error
Expand All @@ -26,6 +28,8 @@
Plot an array (python list)
---------------------------
.. code-block:: python
# plot array
plot([0.1, 0.3, 0.2, 4])
# plot x-y
Expand All @@ -42,6 +46,8 @@
document. In principle, any combination of options is supported, as
long as it makes sense!
.. code-block:: python
a = [0.1, 0.3, 0.2, 4]
plot(a)
import numpy as np
Expand All @@ -62,6 +68,8 @@
he plotSpectrum function of the traditional mantidplot module. This is
a simple example that produces plots of spectra:
.. code-block:: python
# first, load a workspace. You can do this with a Load command or just from the GUI menus
ws = Load("/path/to/MAR11060.raw", OutputWorkspace="foo")
# 1 spectrum plot
Expand All @@ -75,6 +83,8 @@
It is also possible to pass workspace names to plot, as in the
following example:
.. code-block:: python
# please make sure that you use the right path and file name
mar = Load('/path/to/MAR11060.raw', OutputWorkspace="MAR11060")
plot('MAR11060', [10,100,500])
Expand All @@ -83,11 +93,15 @@
Let's load one more workspace so we can see some examples with list of
workspaces
.. code-block:: python
loq=Load('/path/to/LOQ48097.raw', OutputWorkspace="LOQ48097")
The next lines are all equivalent, you can use workspace objects or
names in the list passed to plot:
.. code-block:: python
plot([mar, 'LOQ48097'], [800, 900])
plot([mar, loq], [800, 900])
plot(['MAR11060', loq], [800, 900])
Expand All @@ -96,12 +110,16 @@
these workspaces (instead of the bins or anything else). You can make
that choice more explicit by specifying the 'tool' argument:
.. code-block:: python
plot(['MAR11060', loq], [800, 900], tool='plot_spectrum')
Alternatively, you can use the plot_spectrum command, which is
equivalent to the plot command with the keyword argument
tool='plot_spectrum':
.. code-block:: python
plot_spectrum(['MAR11060', loq], [800, 900])
Plotting bins
Expand All @@ -110,11 +128,15 @@
To plot workspace bins you can use the keyword 'tool' with the value
'plot_bin', like this:
.. code-block:: python
ws = Load('/path/to/HRP39182.RAW', OutputWorkspace="HRP39182")
plot(ws, [1, 5, 7, 100], tool='plot_bin')
or, alternatively, you can use the plot_bin command:
.. code-block:: python
plot_bin(ws, [1, 5, 7, 100], linewidth=4, linestyle=':')
Plotting MD workspaces
Expand All @@ -123,11 +145,15 @@
Similarly, to plot MD workspaces you can use the keyword 'tool' with
the value 'plot_md', like this:
.. code-block:: python
simple_md_ws = CreateMDWorkspace(Dimensions='3',Extents='0,10,0,10,0,10',Names='x,y,z',Units='m,m,m',SplitInto='5',MaxRecursionDepth='20',OutputWorkspace=MDWWorkspaceName)
plot(simple_md_ws, tool='plot_md')
or a specific plot_md command:
.. code-block:: python
plot_md(simple_md_wsws)
For simplicity, these examples use a dummy MD workspace. Please refer
Expand All @@ -141,13 +167,17 @@
You can modify the style of your plots. For example like this (for a
full list of options currently supported, see below).
.. code-block:: python
lines = plot(loq, [100, 104], tool='plot_spectrum', linestyle='-.', marker='*', color='red')
Notice that the plot function returns a list of lines, which
correspond to the spectra lines. At present the lines have limited
functionality. Essentially, the data underlying these lines can be
retrieved as follows:
.. code-block:: python
lines[0].get_xdata()
lines[0].get_ydata()
Expand All @@ -157,16 +187,20 @@
the output lines should be equal to the number of spectra in the
workspace.
To modify the figure, you first need to obtain the figure object
To modify the figure, you first need to obtain the figure object
that represents the figure where the lines are displayed. Once you do
so you can for example set the title of the figure like this:
.. code-block:: python
fig = lines[0].figure()
fig.suptitle('Example figure title')
Other properties can be modified using different functions, as in
matplotlib's pyplot. For example:
.. code-block:: python
title('Test plot of LOQ')
xlabel('ToF')
ylabel('Counts')
Expand All @@ -179,6 +213,8 @@
most recently shown figure). You can also save the current figure into
a file like this:
.. code-block:: python
savefig('example_saved_figure.png')
where the file format is guessed from the file extension. The same
Expand All @@ -195,11 +231,14 @@
There is a couple of important plot options that are set as keyword
arguments:
============ ================
Option name Values supported
------------ ----------------
error_bars True, False (default)
hold on, off
+------------+------------------------+
|Option name | Values supported |
+============+========================+
|error_bars | True, False (default) |
+------------+------------------------+
|hold | on, off |
+------------+------------------------+
error_bars has the same meaning as in the traditional mantidplot plot
functions: it defines whether error bars should be added to the
Expand All @@ -211,12 +250,16 @@
For example, one can add two spectra from a workspace using the
following command:
.. code-block:: python
lines = plot(loq, [100, 102], linestyle='-.', color='red')
But similar results can be obtained by plotting one of the spectra by
a first command, and then plotting the second spectra in a subsequent
command with the hold parameter enabled:
.. code-block:: python
lines = plot(loq, 100, linestyle='-.', color='red')
lines = plot(loq, 102, linestyle='-.', color='blue', hold='on')
Expand All @@ -234,13 +277,17 @@
multi-plot commands (as in pyplot and matlab). For example, you can
type commands like the following:
plot(ws, [100, 101], 'r', ws, [200, 201], 'b', tool='plot_spectrum')
.. code-block:: python
plot(ws, [100, 101], 'r', ws, [200, 201], 'b', tool='plot_spectrum')
This command will plot spectra 100 and 101 in red and spectra 200 and
201 in blue on the same figure. You can also combine different
workspaces, for example:
plot(ws, [100, 101], 'r', mar, [50, 41], 'b', tool='plot_spectrum')
.. code-block:: python
plot(ws, [100, 101], 'r', mar, [50, 41], 'b', tool='plot_spectrum')
Style options supported as keyword arguments
Expand All @@ -250,14 +297,20 @@
all the plot variants. These options have the same (or as closed as
possible) meaning as in matplotlib.
============ ================
Option name Values supported
------------ ----------------
linewidth real values
linestyle '-', '--', '-.' '.'
marker 'o', 'v', '^', '<', '>', 's', '*', 'h', '|', '_'
color color character or string ('b', 'blue', 'g', 'green', 'k', 'black', 'y', 'yellow', 'c', 'cyan', 'r', 'red'. 'm', 'magenta', etc.). RGB colors are not supported at the moment.
============ ================
+------------+---------------------------------------------------------+
|Option name | Values supported |
+============+=========================================================+
|linewidth | real values |
+------------+---------------------------------------------------------+
|linestyle | '-', '--', '-.' '.' |
+------------+---------------------------------------------------------+
|marker | 'o', 'v', '^', '<', '>', 's', '*', 'h', '|', '_' |
+------------+---------------------------------------------------------+
|color | color character or string ('b', 'blue', 'g', 'green', |
| | 'k', 'black', 'y', 'yellow', 'c', 'cyan', 'r', 'red'. |
| | 'm', 'magenta', etc.). RGB colors are not supported at |
| | the moment. |
+------------+---------------------------------------------------------+
Modifying the plot axes
-----------------------
Expand All @@ -266,6 +319,8 @@
seen before. This includes the x and y axis titles, limits and scale
(linear or logarithmic). For example:
.. code-block:: python
ylabel('Counts')
ylim(0, 8)
yscale('log')
Expand All @@ -274,11 +329,12 @@
Axes objects. For this you first need to retrieve the figure and axes
where a plot (or line) has been shown.
.. code-block:: python
lines = plot(mar,[3, 500, 800])
fig = lines[0].figure()
all_ax = fig.axes() # fig.axes() returns in principle a list
ax = all_ax[0] # but we only use one axes
ax.set_ylabel('Counts')
ax.set_xlabel('ToF')
ax.set_ylim(0, 8)
Expand All @@ -305,12 +361,16 @@
This is a limited list of functions that should be sufficient for
basic plots. These functions are presently provided as an example of
this type of interface, and some of them provide functionality
similar or equivalent to several of the keyword arguments for plot
commands detailed in this documentation. Some others produce results
equivalent to the more object oriented methods described above. For
example, the function xlabel is equivalent to the method set_xlabel
applied on the Axes object for the current figure.
this type of interface, and some of them provide functionality similar
or equivalent to several of the keyword arguments for plot commands
detailed in this documentation. Some others produce results equivalent
to the more object oriented methods described above. For example, the
function xlabel is equivalent to the method set_xlabel applied on the
Axes object for the current figure.
Below is the reference documentation of the classes and functions
included in this module.
"""
# Copyright &copy; 2007-2014 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
#
Expand Down

0 comments on commit 832fe21

Please sign in to comment.