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

Legend grouping in bands plots #784

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

pfebrer
Copy link
Contributor

@pfebrer pfebrer commented Jun 4, 2024

This PR solves two problems:

  • Legend grouping of fatbands in matplotlib. Since the "fatband" of each band is drawn as a separate line, the matplotlib backend used to show multiple legend items. Now this is solved by only showing one item:

  • The bands where shown individually on the legend, which often made for a very useless legend. Now all bands are shown as one item in the legend by default. This can be tuned with the group_legend (in bands plots) and bands_group_legend (in fatbands plots) arguments.

import sisl

# First, we create the geometry
BN = sisl.geom.graphene(atoms=["B", "N"])

# Create a hamiltonian with different on-site terms
H = sisl.Hamiltonian(BN)

H[0, 0] = 2
H[1, 1] = -2

H[0, 1] = -2.7
H[1, 0] = -2.7

H[0, 1, (-1, 0)] = -2.7
H[0, 1, (0, -1)] = -2.7
H[1, 0, (1, 0)] = -2.7
H[1, 0, (0, 1)] = -2.7

band = sisl.BandStructure(
    H,
    [[0.0, 0.0], [2.0 / 3, 1.0 / 3], [1.0 / 2, 1.0 / 2], [1.0, 1.0]],
    301,
    [r"Gamma", "K", "M", r"Gamma"],
)

fatbands = band.plot.fatbands(backend="matplotlib")
fatbands.split_groups(name="$species")
fatbands.axes.legend()

Screenshot from 2024-06-05 01-18-31

Reverting legend grouping for bands:

fatbands.update_inputs(bands_group_legend=False).legend()

Screenshot from 2024-06-05 01-23-49

Copy link

codecov bot commented Jun 4, 2024

Codecov Report

Attention: Patch coverage is 69.04762% with 13 lines in your changes missing coverage. Please review.

Project coverage is 87.35%. Comparing base (1d3f4da) to head (d3a6b90).

Files Patch % Lines
src/sisl/viz/processors/bands.py 41.66% 7 Missing ⚠️
src/sisl/viz/plots/bands.py 85.00% 3 Missing ⚠️
src/sisl/viz/figure/matplotlib.py 50.00% 2 Missing ⚠️
src/sisl/viz/plotters/xarray.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #784   +/-   ##
=======================================
  Coverage   87.34%   87.35%           
=======================================
  Files         396      396           
  Lines       50750    50757    +7     
=======================================
+ Hits        44330    44340   +10     
+ Misses       6420     6417    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zerothi zerothi merged commit 8659a4a into zerothi:main Jun 5, 2024
8 of 9 checks passed
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.

2 participants