Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 151ddf9

Browse files
Run ruff format
1 parent 54283bf commit 151ddf9

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

‎plotly/matplotlylib/renderer.py‎

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,9 @@ def open_legend(self, legend, props):
213213
self._processing_legend = True
214214
self._legend_visible = props.get("visible", True)
215215
if self._legend_visible:
216-
self.msg += " Enabling native plotly legend (matplotlib legend is visible)\n"
216+
self.msg += (
217+
" Enabling native plotly legend (matplotlib legend is visible)\n"
218+
)
217219
self.plotly_fig["layout"]["showlegend"] = True
218220
else:
219221
self.msg += " Not enabling legend (matplotlib legend is not visible)\n"
@@ -229,7 +231,6 @@ def close_legend(self, legend):
229231
self._legend_visible = False
230232

231233
def draw_bars(self, bars):
232-
233234
# sort bars according to bar containers
234235
mpl_traces = []
235236
for container in self.bar_containers:
@@ -330,7 +331,7 @@ def draw_bar(self, coll):
330331
) # TODO ditto
331332
if len(bar["x"]) > 1:
332333
self.msg += " Heck yeah, I drew that bar chart\n"
333-
self.plotly_fig.add_trace(bar),
334+
self.plotly_fig.add_trace(bar)
334335
if bar_gap is not None:
335336
self.plotly_fig["layout"]["bargap"] = bar_gap
336337
else:
@@ -451,13 +452,13 @@ def draw_marked_line(self, **props):
451452
marked_line["x"] = mpltools.mpl_dates_to_datestrings(
452453
marked_line["x"], formatter
453454
)
454-
self.plotly_fig.add_trace(marked_line),
455+
self.plotly_fig.add_trace(marked_line)
455456
self.msg += " Heck yeah, I drew that line\n"
456457
elif props["coordinates"] == "axes":
457458
# dealing with legend graphical elements
458459
self.msg += " Using native legend\n"
459460
else:
460-
self.msg += " Line didn't have 'data' coordinates, ""not drawing\n"
461+
self.msg += " Line didn't have 'data' coordinates, not drawing\n"
461462
warnings.warn(
462463
"Bummer! Plotly can currently only draw Line2D "
463464
"objects from matplotlib that are in 'data' "
@@ -521,7 +522,7 @@ def draw_path_collection(self, **props):
521522
self.msg += " Drawing path collection as markers\n"
522523
self.draw_marked_line(**scatter_props)
523524
else:
524-
self.msg += " Path collection not linked to 'data', ""not drawing\n"
525+
self.msg += " Path collection not linked to 'data', not drawing\n"
525526
warnings.warn(
526527
"Dang! That path collection is out of this "
527528
"world. I totally don't know what to do with "
@@ -622,13 +623,17 @@ def draw_text(self, **props):
622623
else: # just a regular text annotation...
623624
self.msg += " Text object is a normal annotation\n"
624625
# Skip creating annotations for legend text when using native legend
625-
if self._processing_legend and self._legend_visible and props["coordinates"] == "axes":
626-
self.msg += " Skipping legend text annotation (using native legend)\n"
627-
return
628-
if props["coordinates"] != "data":
626+
if (
627+
self._processing_legend
628+
and self._legend_visible
629+
and props["coordinates"] == "axes"
630+
):
629631
self.msg += (
630-
" Text object isn't linked to 'data' ""coordinates\n"
632+
" Skipping legend text annotation (using native legend)\n"
631633
)
634+
return
635+
if props["coordinates"] != "data":
636+
self.msg += " Text object isn't linked to 'data' coordinates\n"
632637
x_px, y_px = (
633638
props["mplobj"].get_transform().transform(props["position"])
634639
)
@@ -638,7 +643,7 @@ def draw_text(self, **props):
638643
xanchor = props["style"]["halign"] # no difference here!
639644
yanchor = mpltools.convert_va(props["style"]["valign"])
640645
else:
641-
self.msg += " Text object is linked to 'data' ""coordinates\n"
646+
self.msg += " Text object is linked to 'data' coordinates\n"
642647
x, y = props["position"]
643648
axis_ct = self.axis_ct
644649
xaxis = self.plotly_fig["layout"]["xaxis{0}".format(axis_ct)]
@@ -714,9 +719,7 @@ def draw_title(self, **props):
714719
"""
715720
self.msg += " Attempting to draw a title\n"
716721
if len(self.mpl_fig.axes) > 1:
717-
self.msg += (
718-
" More than one subplot, adding title as " "annotation\n"
719-
)
722+
self.msg += " More than one subplot, adding title as annotation\n"
720723
x_px, y_px = props["mplobj"].get_transform().transform(props["position"])
721724
x, y = mpltools.display_to_paper(x_px, y_px, self.plotly_fig["layout"])
722725
annotation = go.layout.Annotation(
@@ -734,9 +737,7 @@ def draw_title(self, **props):
734737
)
735738
self.plotly_fig["layout"]["annotations"] += (annotation,)
736739
else:
737-
self.msg += (
738-
" Only one subplot found, adding as a " "plotly title\n"
739-
)
740+
self.msg += " Only one subplot found, adding as a plotly title\n"
740741
self.plotly_fig["layout"]["title"] = props["text"]
741742
title_font = dict(
742743
size=props["style"]["fontsize"], color=props["style"]["color"]

‎plotly/matplotlylib/tests/test_renderer.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ def test_legend_disabled_when_no_matplotlib_legend():
4444

4545
# Should not have showlegend explicitly set to True
4646
# (Plotly's default behavior when no legend elements exist)
47-
assert not hasattr(plotly_fig.layout, 'showlegend') or plotly_fig.layout.showlegend != True
47+
assert (
48+
not hasattr(plotly_fig.layout, "showlegend")
49+
or plotly_fig.layout.showlegend != True
50+
)
4851

4952

5053
def test_legend_disabled_when_matplotlib_legend_not_visible():
@@ -57,15 +60,18 @@ def test_legend_disabled_when_matplotlib_legend_not_visible():
5760
plotly_fig = tls.mpl_to_plotly(fig)
5861

5962
# Should not enable legend when matplotlib legend is hidden
60-
assert not hasattr(plotly_fig.layout, 'showlegend') or plotly_fig.layout.showlegend != True
63+
assert (
64+
not hasattr(plotly_fig.layout, "showlegend")
65+
or plotly_fig.layout.showlegend != True
66+
)
6167

6268

6369
def test_multiple_traces_native_legend():
6470
"""Test native legend works with multiple traces of different types."""
6571
fig, ax = plt.subplots()
66-
ax.plot([0, 1, 2], [0, 1, 0], '-', label="Line")
67-
ax.plot([0, 1, 2], [1, 0, 1], 'o', label="Markers")
68-
ax.plot([0, 1, 2], [0.5, 0.5, 0.5], 's-', label="Line+Markers")
72+
ax.plot([0, 1, 2], [0, 1, 0], "-", label="Line")
73+
ax.plot([0, 1, 2], [1, 0, 1], "o", label="Markers")
74+
ax.plot([0, 1, 2], [0.5, 0.5, 0.5], "s-", label="Line+Markers")
6975
ax.legend()
7076

7177
plotly_fig = tls.mpl_to_plotly(fig)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /