Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Alexboiboi
Copy link
Member

@Alexboiboi Alexboiboi commented Jun 4, 2024

Related Issues

Notes

This adds a new units_length parameter to the show function and allows the user to choose the length units for displaying Magpylib objects per-row-and-column.

Side effects

  • The zoom parameter is now also per-row-and-column.
  • Ranges are individual for each plot and not overall like before.
  • Pyvista plots have grids visible by default to show axes labels
  • colors are iterating over subplots (before, a new cycle started for each subplot)

Examples

import magpylib as magpy

c1 = magpy.magnet.Cuboid(
    dimension=(1, 1, 1),
    polarization=(1, 2, 3),
)

with magpy.show_context(c1, backend="matplotlib") as s:
    s.show(row=1, col=1, units_length="m", zoom=3)
    s.show(row=1, col=2, units_length="dm", zoom=2)
    s.show(row=2, col=1, units_length="cm", zoom=1)
    s.show(row=2, col=2, units_length="mm", zoom=0)

image

Tasks

  • Allow length units:
    • classic ones ['ym', 'zm', 'am', 'fm', 'pm', 'nm', 'µm', 'mm', 'm', 'km', 'Mm', 'Gm', 'Tm', 'Pm', 'Em', 'Zm', 'Ym']
    • "dm" and cm (only for manuel entry, "auto" will not infer these
    • None defaults to SI (m) and does not show unit in axes labels
    • "auto" will infer a suitable length unit depending on the max range value for each subplot independently
    • define default value ("m", "auto" or None)
  • Adapt ranges to units per row-col-combination.
  • Catch inconsistent identifiers (zoom, units_length, etc. ) as per row-col basis.
  • Ensure all elements are correctly scaled
    • paths
    • arrows
    • meshes
    • extra generic traces
    • extra non generic traces
  • Pass on right unit in axes labels
    • matplotlib
    • plotly
    • pyvista
  • Docs: add or modify an example to reflect the changes
  • Testing: add unit tests to cover the common and edge cases
  • Changelog: document new feature

@Alexboiboi Alexboiboi requested a review from OrtnerMichael June 4, 2024 12:12
@Alexboiboi Alexboiboi self-assigned this Jun 4, 2024
@Alexboiboi Alexboiboi marked this pull request as ready for review June 4, 2024 16:08
@Alexboiboi Alexboiboi linked an issue Jun 4, 2024 that may be closed by this pull request
@Alexboiboi Alexboiboi marked this pull request as draft June 10, 2024 14:10
@Alexboiboi Alexboiboi marked this pull request as ready for review June 12, 2024 07:24
@Alexboiboi
Copy link
Member Author

I think default should be "auto"! I think it should not be None. Any reason it should be "m" ?

  • default SI unit
  • but lots of ppl working with mm and um will have 1e-3 and 1e-6 on their figures ... better to make use of the nice auto-feature.

Hi @OrtnerMichael,

I the overwhelming majority of cases this is nice of course. We however have an example in the docs with the pyvista streamlines, where letting the system choose leads to unexpected results (cylinder is in mm but streamlines assume meters):
image

@OrtnerMichael OrtnerMichael merged commit 0f5f13e into main Jun 20, 2024
@OrtnerMichael OrtnerMichael deleted the show-units branch June 20, 2024 14:25
@OrtnerMichael OrtnerMichael mentioned this pull request Oct 9, 2024
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 this pull request may close these issues.

Add units choice to the show function
2 participants