Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit e73152d

Browse files
Dimitar Tasevdtasev
authored andcommitted
Adds some help for plotly
1 parent d959a05 commit e73152d

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

WebApp/autoreduce_webapp/templates/help.html

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,48 @@ <h3>How do I save out plots from my reduce.py?</h3>
436436
<pre><code class="language-python"> ... some plotting code with matplotlib ...
437437

438438
filename = get_name_of_data_file(input_file)
439-
my_matplotlib_figure.savefig(os.path.join(output_dir, f"{filename}.png"), dpi=None)
440-
</code></pre>
439+
my_matplotlib_figure.savefig(os.path.join(output_dir, f"{filename}.png"), dpi=None)</code></pre>
441440
</div>
442441
</section>
443-
<section class="help-topic panel panel-default" data-category="question"
442+
<section class="help-topic panel panel-default" data-category="question">
443+
<div class="panel-heading">
444+
<h3>How do I save out interactive plots with Plotly?</h3>
445+
</div>
446+
<div class="panel-body">
447+
<p>To get an interactive plot in the webapp you need to do the plotting with <strong>Plotly</strong> and save it to a .json file.</p>
448+
<pre><code class="language-xml">&lt;name-part-of-the-data-file&gt;.json</code></pre>
449+
<p>where e.g. if the data file is "GEM90963.nxs" then "GEM90963" is the <code>name-part-of-the-data-file</code>,
450+
and the plot file extension must be "json".</p>
451+
452+
<p>The save code that you need in the reduction script is:</p>
453+
<pre><code class="language-python"># Serialise the figure to a JSON that can be shown in the webapp
454+
figure_json = my_plotly_figure.to_json()
455+
456+
# Save the file in the output_dir
457+
filename = get_name_of_data_file(input_file)
458+
with open(os.path.join(output_dir, f"{filename}.json")) as figfile:
459+
figfile.write(figure_json)</code></pre>
460+
<p>Note: the above uses Python 3's <a href="https://www.python.org/dev/peps/pep-0498/">f-string</a> syntax to make the output JSON filename.</p>
461+
</section>
462+
<section class="help-topic panel panel-default" data-category="question">
463+
<div class="panel-heading">
464+
<h3>Plotting with Plotly</h3>
465+
</div>
466+
<div class="panel-body">
467+
<p>Plotly is slightly different from Matplotlib, but the difference is mostly in the syntax, while the fundamental features remain the same.
468+
As long as Plotly successfully serialises the plot <code>to_json</code>, it should also work in the webapp.</p>
469+
<p>Because Mantid integrates Matplotlib, it is <strong>not possible</strong> to plot workspaces directly into Plotly. You will have to extract the data manually via the <code>readX</code>, <code>readY</code>, and similar methods.</p>
470+
<p>To avoid adding plotting code here that will get out of date, it is recommended to have a look at the <a href="https://plotly.com/python/line-and-scatter/#scatter-and-line-plot-with-goscatter">documentation</a>.</p>
471+
<section class="help-topic panel panel-default" data-category="question">
472+
<div class="panel-heading">
473+
<h3>Plotly express or graphics_objects (go)?</h3>
474+
</div>
475+
<div class="panel-body">
476+
<p>Both of Plotly's plotting APIs should work. Just use whatever works best for your case.</p>
477+
</div>
478+
</section>
479+
</section>
480+
<section class="help-topic panel panel-default" data-category="question"
444481
data-topics="output type structure reduction directory format">
445482
<div class="panel-heading">
446483
<h3>What are the output structures available in autoreduction?</h3>

0 commit comments

Comments
 (0)