Skip to content

Commit

Permalink
Fixed matplotlib fatbands and enabled opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
pfebrer committed Nov 7, 2024
1 parent 309d393 commit cd8b990
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
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 @@ def _plotly_dash_to_matplotlib(self, dash: str) -> str:
return {
"dash": "dashed",
"dot": "dotted",
None: "solid",
}.get(dash, dash)

def _sanitize_colorscale(self, colorscale):
Expand Down Expand Up @@ -380,6 +381,8 @@ def draw_multisize_line(
# 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

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

Expand Down Expand Up @@ -411,11 +414,21 @@ def draw_area_line(

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 @@ def draw_scatter(
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

0 comments on commit cd8b990

Please sign in to comment.