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

Fixed matplotlib fatbands and enabled opacity #862

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/sisl/viz/figure/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@
return {
"dash": "dashed",
"dot": "dotted",
None: "solid",
}.get(dash, dash)

def _sanitize_colorscale(self, colorscale):
Expand Down Expand Up @@ -380,6 +381,8 @@
# Set the values used for colormapping
lc.set_linewidth(line.get("width", 1))
lc.set_linestyle(self._plotly_dash_to_matplotlib(line.get("dash", "solid")))
lc.set_color(line.get("color"))
lc.set_alpha(line.get("opacity"))

Check warning on line 385 in src/sisl/viz/figure/matplotlib.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/figure/matplotlib.py#L384-L385

Added lines #L384 - L385 were not covered by tests
Copy link
Owner

Choose a reason for hiding this comment

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

a bit pedantic here, but matplotlib users are used to using alpha=, could it allow both things?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would become a complete chaos if I try to support all keywords of all backends 😅
I took the decision to stick to plotly terminology in general to make things easier to maintain and document.

Copy link
Owner

Choose a reason for hiding this comment

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

ok, fair...


axes = _axes or self._get_subplot_axes(row=row, col=col)

Expand Down Expand Up @@ -411,11 +414,21 @@

if dependent_axis in ("y", None):
axes.fill_between(
x, y + spacing, y - spacing, color=line.get("color"), label=name
x,
y + spacing,
y - spacing,
color=line.get("color"),
label=name,
alpha=line.get("opacity"),
)
elif dependent_axis == "x":
axes.fill_betweenx(
y, x + spacing, x - spacing, color=line.get("color"), label=name
y,
x + spacing,
x - spacing,
color=line.get("color"),
label=name,
alpha=line.get("opacity"),
)
else:
raise ValueError(
Expand All @@ -435,6 +448,7 @@
col=None,
_axes=None,
meta={},
legendgroup=None,
**kwargs,
):
axes = _axes or self._get_subplot_axes(row=row, col=col)
Expand Down
1 change: 1 addition & 0 deletions src/sisl/viz/figure/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ def draw_area_line(
"legendgroup": name,
"showlegend": kwargs.pop("showlegend", None),
"fill": "toself",
"opacity": line.get("opacity"),
"meta": kwargs.pop("meta", {}),
},
row=row,
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/viz/plots/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def fatbands_plot(
orb_dim="orb",
spin_dim="spin",
sanitize_group=orbital_manager,
group_vars=("color", "dash"),
group_vars=("color", "dash", "opacity"),
groups_dim="group",
drop_empty=True,
spin_reduce=False,
Expand Down