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

Allow dash to be set in bands plots. #780

Merged
merged 1 commit into from
May 30, 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
10 changes: 10 additions & 0 deletions src/sisl/viz/figure/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@
def show(self, *args, **kwargs):
return self.figure.show(*args, **kwargs)

def _plotly_dash_to_matplotlib(self, dash: str) -> str:

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

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/figure/matplotlib.py#L236

Added line #L236 was not covered by tests
"""Converts a plotly line_dash specification to a matplotlib linestyle."""
return {

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

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/figure/matplotlib.py#L238

Added line #L238 was not covered by tests
"dash": "dashed",
"dot": "dotted",
}.get(dash, dash)

def draw_line(
self,
x,
Expand All @@ -256,6 +263,7 @@
y,
color=line.get("color"),
linewidth=line.get("width", 1),
linestyle=self._plotly_dash_to_matplotlib(line.get("dash", "solid")),
marker=marker_format,
markersize=marker.get("size"),
markerfacecolor=marker_color,
Expand Down Expand Up @@ -310,6 +318,7 @@
# Set the values used for colormapping
lc.set_array(line.get("color"))
lc.set_linewidth(line.get("width", 1))
lc.set_linestyle(self._plotly_dash_to_matplotlib(line.get("dash", "solid")))

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

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/figure/matplotlib.py#L321

Added line #L321 was not covered by tests

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

Expand Down Expand Up @@ -337,6 +346,7 @@

# 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")))

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

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/figure/matplotlib.py#L349

Added line #L349 was not covered by tests

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

Expand Down
7 changes: 6 additions & 1 deletion src/sisl/viz/plots/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def bands_plot(
E_axis: Literal["x", "y"] = "y",
bands_range: Optional[Tuple[int, int]] = None,
spin: Optional[Literal[0, 1]] = None,
bands_style: StyleSpec = {"color": "black", "width": 1, "opacity": 1},
bands_style: StyleSpec = {
"color": "black",
"width": 1,
"opacity": 1,
"dash": "solid",
},
spindown_style: StyleSpec = {"color": "blue", "width": 1},
colorscale: Optional[str] = None,
gap: bool = False,
Expand Down
2 changes: 1 addition & 1 deletion src/sisl/viz/processors/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@
default_styles = {"color": "black", "width": 1, "opacity": 1}
for key in default_styles:
if key not in bands_data.data_vars and key not in bands_style:
bands_style[key] = default_styles[key]

Check failure

Code scanning / CodeQL

Modification of parameter with default Error

This expression mutates a
default value
.
This expression mutates a
default value
.
This expression mutates a
default value
.

# If some key in bands_style is a callable, apply it
for key in bands_style:
if callable(bands_style[key]):
bands_style[key] = bands_style[key](data=bands_data)

Check failure

Code scanning / CodeQL

Modification of parameter with default Error

This expression mutates a
default value
.
This expression mutates a
default value
.
This expression mutates a
default value
.

# Build the style dataarrays
if "spin" in bands_data.dims:
Expand All @@ -128,7 +128,7 @@
)
else:
style_arrays = {}
for key in ["color", "width", "opacity"]:
for key in ["color", "width", "opacity", "dash"]:

Check warning on line 131 in src/sisl/viz/processors/bands.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/viz/processors/bands.py#L131

Added line #L131 was not covered by tests
style_arrays[key] = xr.DataArray(bands_style[key])

# Merge the style arrays with the bands dataset and return the styled dataset
Expand Down
Loading