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

Add Matplotlib magnetization coloring #597

Merged
merged 16 commits into from Jun 23, 2023
Merged

Add Matplotlib magnetization coloring #597

merged 16 commits into from Jun 23, 2023

Conversation

Alexboiboi
Copy link
Member

@Alexboiboi Alexboiboi commented Mar 16, 2023

Scope

When using the matplotlib library there is no straightforward way to plot color gradients properly in 3D. In this PR, a new set of utilities allows to plot the magnetization orientation over every magnet by slicing and retriangulate the underlying graphical mesh object.

Examples

This is how it looks like

  • in qt from a script

image

- in jupyter notebook

image

Caveats

So far it is an opt-in behavior, and we need to decide if we make it the new default for the matplotlib backend.
There are a few caveat though that will influence this decision:

  • The slicing tends to exacerbate the classical underlying matplotlib issue of bad 3D layering. See example below

image

  • Without deactivating ant-aliasing it is impossible to make the triangle edges disappear. And without antialiasing, the plots looks much uglier in the jupyter notebook, since the dpi is set to 80. If we increase dpi, the plots are getting huge.
    This is how it looks so far:

Antialiasing OFF:

  • QT from script:

image

  • jupyter

image

Antialiasing ON:

  • QT from script:

image

  • jupyter

image

###Notes

Open Tasks

  • Make it the new default, or not
  • Keep default dpi
  • Make docs nicer by enforcing svg output (only for the docs)
  • @OrtnerMichael feedback

Please @OrtnerMichael try out the feature and help us make the decision on how to move forward ;)

@@ -39,6 +39,7 @@
from magpylib._src.display.traces_utility import merge_mesh3d
from magpylib._src.display.traces_utility import merge_traces
from magpylib._src.display.traces_utility import place_and_orient_model3d
from magpylib._src.display.traces_utility import slice_mesh_from_colorscale

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
magpylib._src.display.traces_utility
begins an import cycle.
@codecov-commenter
Copy link

codecov-commenter commented Mar 17, 2023

Codecov Report

Merging #597 (c861a25) into main (0e93067) will decrease coverage by 0.13%.
The diff coverage is 98.27%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #597      +/-   ##
==========================================
- Coverage   99.80%   99.68%   -0.13%     
==========================================
  Files          54       54              
  Lines        6218     6296      +78     
==========================================
+ Hits         6206     6276      +70     
- Misses         12       20       +8     
Impacted Files Coverage Δ
magpylib/_src/fields/field_wrap_BH.py 100.00% <ø> (ø)
magpylib/_src/display/backend_matplotlib.py 97.80% <75.00%> (-2.20%) ⬇️
magpylib/_src/display/traces_base.py 100.00% <100.00%> (ø)
magpylib/_src/display/traces_generic.py 99.00% <100.00%> (-1.00%) ⬇️
magpylib/_src/display/traces_utility.py 100.00% <100.00%> (ø)
magpylib/_src/obj_classes/class_BaseDisplayRepr.py 100.00% <100.00%> (ø)

magpylib/_src/display/traces_base.py Dismissed Show dismissed Hide dismissed
@OrtnerMichael
Copy link
Member

decision:

  • coloring default in matplotlib (its crappy no matter what)
  • antialiased= True
  • keep default dpi

@Alexboiboi Alexboiboi added this to the 4.3 milestone Jun 22, 2023
@Alexboiboi
Copy link
Member Author

@OrtnerMichael, ready to merge

Copy link
Member

@OrtnerMichael OrtnerMichael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good ty.
we should think about making pyvista or plotly the default backend

@OrtnerMichael OrtnerMichael merged commit 4feb7ac into main Jun 23, 2023
11 checks passed
@OrtnerMichael OrtnerMichael deleted the mpl-mag-color branch June 23, 2023 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants