Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogNorm and vmin cannot be used simultaneously #26

Open
RemDelaporteMathurin opened this issue Feb 14, 2022 · 4 comments · Fixed by #37
Open

LogNorm and vmin cannot be used simultaneously #26

RemDelaporteMathurin opened this issue Feb 14, 2022 · 4 comments · Fixed by #37

Comments

@RemDelaporteMathurin
Copy link
Member

plot = plot_regular_mesh_tally_with_geometry(
    tally=my_tally_xz,
    dagmc_file_or_trimesh_object="dagmc_not_merged.h5m",
    plane_origin=(0, 0, 0),
    plane_normal=[0, 1, 0],
    rotate_geometry=90,
    source_strength=source_strength,
    scale=LogNorm(),
    vmin=1e-3,
    label="Tritium generation (T/m3/s)",
    filename="my_tally_xz.png",
)

produces

  File "convert_results.py", line 24, in <module>
    plot = plot_regular_mesh_tally_with_geometry(
  File "/home/regular_mesh_plotter/regular_mesh_plotter/core.py", line 142, in plot_regular_mesh_tally_with_geometry
    plot = plot_regular_mesh_values(
  File "/home/regular_mesh_plotter/regular_mesh_plotter/core.py", line 48, in plot_regular_mesh_values
    image_map = plt.imshow(values, norm=scale, vmin=vmin, extent=extent, origin='lower')
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/_api/deprecation.py", line 456, in wrapper
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/pyplot.py", line 2640, in imshow
    __ret = gca().imshow(
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/_api/deprecation.py", line 456, in wrapper
    return func(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/__init__.py", line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 5447, in imshow
    im._scale_norm(norm, vmin, vmax)
  File "/opt/conda/lib/python3.8/site-packages/matplotlib/cm.py", line 380, in _scale_norm
    raise ValueError(
ValueError: Passing parameters norm and vmin/vmax simultaneously is not supported. Please pass vmin/vmax directly to the norm when creating it.
@shimwell
Copy link
Member

ah that is caused by this line, not quite sure how to apply vmin and scale separately.

https://github.com/fusion-energy/regular_mesh_plotter/blob/c5dbff275d56aaef8ec65fd7d85fc43091e6e8ee/regular_mesh_plotter/core.py#L48

@RemDelaporteMathurin
Copy link
Member Author

So vmin and vmax only influence the colorbar.
If specifying the norm, you can do :

plot = plot_regular_mesh_tally_with_geometry(
    tally=my_tally_xz,
    dagmc_file_or_trimesh_object="dagmc_not_merged.h5m",
    plane_origin=(0, 0, 0),
    plane_normal=[0, 1, 0],
    rotate_geometry=90,
    source_strength=source_strength,
    scale=LogNorm(vmin=1e-3),
    label="Tritium generation (T/m3/s)",
    filename="my_tally_xz.png",
)

@RemDelaporteMathurin
Copy link
Member Author

But vmin and vmax only change the colorbar, not the actual data, in the sense that it doesn't mask the data below or above this threshold.

It would be a very nice feature:
https://stackoverflow.com/questions/32991649/matplotlib-imshow-how-to-apply-a-mask-on-the-matrix

@RemDelaporteMathurin
Copy link
Member Author

I think this will be fixed in #37

@RemDelaporteMathurin RemDelaporteMathurin linked a pull request Jun 22, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants