Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outline plot area in plotly in Python

Tags:

python

plotly

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?

like image 206
wordsforthewise Avatar asked Feb 07 '17 17:02

wordsforthewise


1 Answers

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

like image 122
Maximilian Peters Avatar answered Oct 12 '22 12:10

Maximilian Peters