fusion-energy / openmc_regular_mesh_plotter

A Python package for plotting OpenMC regular mesh tally results with underlying geometry from neutronics simulations.
MIT License
9 stars 1 forks source link

Bug in README #36

Closed RemDelaporteMathurin closed 10 months ago

RemDelaporteMathurin commented 2 years ago

In the README, the syntax is:

my_plot = rmp.plot_regular_mesh_tally(
    tally=tally2,
    std_dev_or_tally_value="tally_value",
    x_label="X [cm]",
    y_label="Y [cm]",
)

my_plot .save_fig("openmc_mesh_tally_plot.png")

but this produces the following error:

Traceback (most recent call last):
  File "/home/fusion-neutronics-workflow/examples/post_processing.py", line 21, in <module>
    my_plot.save_fig("openmc_mesh_tally_plot.png")
AttributeError: module 'matplotlib.pyplot' has no attribute 'save_fig'

That's because the function plot_regular_mesh_values returns the matplotlib.pyplot module instead of the figure itself.

https://github.com/fusion-energy/regular_mesh_plotter/blob/1e422f2dff93e3ec093961791fd1e29ebf2f1bb4/regular_mesh_plotter/core.py#L66

I think these functions shouldn't return anything (apart the current ax maybe) and users should handle everything in matplotlib directly.

RemDelaporteMathurin commented 2 years ago

mind you, it may work with savefig instead of save_fig.

RemDelaporteMathurin commented 2 years ago

Anyway, the usage should be imho:

import matplotlib.pyplot as plt
my_plot = rmp.plot_regular_mesh_tally(
    tally=tally2,
    std_dev_or_tally_value="tally_value",
    x_label="X [cm]",
    y_label="Y [cm]",
)

plt.ylabel("my custom y label")
plt.savefig("openmc_mesh_tally_plot.png")