15

I've made a figure in plotly, e.g.:

import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Scatter(
    x=[1, 2, 3, 4, 5, 6, 7],
    y=[7, 6, 5, 4, 3, 2, 1]
)
trace2 = go.Scatter(
    x=[1, 2, 3, 4, 5, 6, 7, 8],
    y=[1, 2, 3, 4, 5, 6, 7, 8]
)
data = [trace1, trace2]
layout = dict(xaxis = dict(title = 'T (K)', showgrid=False, ticks='inside'),
                yaxis = dict(title = 'normalized intensity', showgrid=False, ticks='inside'),
                font=dict(size=18),
                )
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, auto_open=True, filename='test_fig.png')
py.image.save_as(fig, filename='test_fig.png')

and the figure looks like:

test figure

I'd like an outline of the plot area like so:

outlined fig

but I am unable to figure it out from the plot.ly docs so far. Is this possible?

1
  • 1
    setting showline=True in each axis dictionary will give you the left and bottom lines, not sure if top and right are possible though. Commented Feb 7, 2017 at 17:45

1 Answer 1

31

All you need is to find another well hidden Plotly attribute. In this case it is mirror.

mirror (enumerated: True | "ticks" | False | "all" | "allticks" )

Determines if the axis lines or/and ticks are mirrored to the opposite side of the plotting area. If "True", the axis lines are mirrored. If "ticks", the axis lines and ticks are mirrored. If "False", mirroring is disable. If "all", axis lines are mirrored on all shared-axes subplots. If "allticks", axis lines and ticks are mirrored on all shared-axes subplots.

Add

mirror=True,
ticks='outside',
showline=True,

to your xaxis and yaxis dicts and you get the following graph.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Hah thanks. I'd say 'well-hidden' is not a good property of methods/attributes of a programming library.
@wordsforthewise: Well to Plotly's defense, it is shown on the example pages but googling won't help you because the essential keywords are missing. plot.ly/python/axes/#styling-and-coloring-axes-and-the-zeroline

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.