Skip to content

Set axis linecolor to black by default when converting from matplotlib #5311

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions plotly/matplotlylib/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,16 @@ def open_axes(self, ax, props):
self.axis_ct += 1
# set defaults in axes
xaxis = go.layout.XAxis(
anchor="y{0}".format(self.axis_ct), zeroline=False, ticks="inside"
anchor="y{0}".format(self.axis_ct),
zeroline=False,
ticks="inside",
linecolor="black",
)
yaxis = go.layout.YAxis(
anchor="x{0}".format(self.axis_ct), zeroline=False, ticks="inside"
anchor="x{0}".format(self.axis_ct),
zeroline=False,
ticks="inside",
linecolor="black",
)
# update defaults with things set in mpl
mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis(
Expand Down Expand Up @@ -299,7 +305,7 @@ def draw_bar(self, coll):
) # TODO ditto
if len(bar["x"]) > 1:
self.msg += " Heck yeah, I drew that bar chart\n"
(self.plotly_fig.add_trace(bar),)
self.plotly_fig.add_trace(bar)
if bar_gap is not None:
self.plotly_fig["layout"]["bargap"] = bar_gap
else:
Expand Down Expand Up @@ -497,7 +503,7 @@ def draw_marked_line(self, **props):
marked_line["x"] = mpltools.mpl_dates_to_datestrings(
marked_line["x"], formatter
)
(self.plotly_fig.add_trace(marked_line),)
self.plotly_fig.add_trace(marked_line)
self.msg += " Heck yeah, I drew that line\n"
elif props["coordinates"] == "axes":
# dealing with legend graphical elements
Expand Down
4 changes: 4 additions & 0 deletions plotly/matplotlylib/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt
13 changes: 13 additions & 0 deletions plotly/matplotlylib/tests/test_renderer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import plotly.tools as tls

from . import plt


def test_axis_linecolor_defaults_to_black():
fig, ax = plt.subplots()
ax.plot([0, 1], [0, 1])

plotly_fig = tls.mpl_to_plotly(fig)

assert plotly_fig.layout.xaxis.linecolor == "black"
assert plotly_fig.layout.yaxis.linecolor == "black"