-
-
Notifications
You must be signed in to change notification settings - Fork 9
[315] Legend groups #349
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
base: main
Are you sure you want to change the base?
[315] Legend groups #349
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
from typing import Any, TypedDict | ||
|
||
|
||
class Font(TypedDict, total=False): | ||
# plotly/graph_objs/scatter/legendgrouptitle/_font.py | ||
color: str | None | ||
family: str | None | ||
lineposition: str | None | ||
shadow: str | None | ||
size: int | float | None | ||
style: str | None | ||
textcase: str | None | ||
variant: str | None | ||
weight: int | None | ||
|
||
|
||
class Legendgrouptitle(TypedDict, total=False): | ||
# plotly/graph_objs/scatter/_legendgrouptitle.py | ||
text: str | None | ||
font: Font | None | ||
|
||
|
||
@dataclasses.dataclass | ||
class LegendContext: | ||
name: str | ||
showlegend: bool | ||
legendgroup: str | int | float | None = None | ||
legendgrouptitle: Legendgrouptitle | None = None | ||
|
||
@property | ||
def trace_kwargs(self) -> dict[str, Any]: | ||
return dataclasses.asdict(self) | ||
|
||
|
||
class LegendContextManager: | ||
def __init__(self, legendgroup: bool) -> None: | ||
super().__init__() | ||
self.legendgroup = legendgroup | ||
self._seen_labels: set[str] = set() | ||
|
||
def get_legend_ctx(self, label: str) -> LegendContext: | ||
if not self.legendgroup: | ||
return LegendContext(name=label, showlegend=True) | ||
if label not in self._seen_labels: | ||
self._seen_labels.add(label) | ||
return LegendContext( | ||
name=label, | ||
showlegend=True, | ||
legendgroup=label, | ||
# FIXME: This doesn't seem to work as expected | ||
# legendgrouptitle=Legendgrouptitle(text=label), | ||
) | ||
return LegendContext( | ||
name=label, | ||
showlegend=False, | ||
legendgroup=label, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ def ridgeplot( | |
trace_type: TraceTypesArray | ShallowTraceTypesArray | TraceType | None = None, | ||
labels: LabelsArray | ShallowLabelsArray | None = None, | ||
row_labels: Collection[str] | None | Literal[False] = None, | ||
legendgroup: bool = False, # TODO: document and rename to smth better! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TODO comment suggests this parameter needs documentation and a better name. The current name 'legendgroup' and the boolean type don't clearly convey that this enables grouping of legend entries by label name. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
# KDE parameters | ||
kernel: str = "gau", | ||
bandwidth: KDEBandwidth = "normal_reference", | ||
|
@@ -503,6 +504,7 @@ def ridgeplot( | |
trace_labels=labels, | ||
trace_types=trace_type, | ||
row_labels=row_labels, | ||
legendgroup=legendgroup, | ||
colorscale=colorscale, | ||
colormode=colormode, | ||
color_discrete_map=color_discrete_map, | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented FIXME indicates that legendgrouptitle functionality is not working as expected. This suggests there may be an issue with the Plotly legend group title feature that should be investigated or documented.
Copilot uses AI. Check for mistakes.