Reputation: 55
I have been doing some experimenting at replacing my matplotlib plots using the plot.ly library inside the ipython notebook. Basically the problem I have is that plot.ly plots that are autosized don't look very good and I have tried to manually tweak them but they always get chopped up in the vertical direction of the notebook.
I often do plots that are arrayed in N rows x 2 or 3 cols. The data for these plots often comes from a pandas data frame with a Multi-index with many keys. The plots usually are data vs index position with tick labels that match the index keys. So the tick labels are usually long strings and are never shared among the plots (shared axes is no go). Matplotlib output in the ipython notebook will render things such that they generally scale as long as is needed in the vertical direction. A little manual tweaking and things look ok.
Plot.ly output in the notebook seems to be limited in this regard. I modified some plot.ly demo code and in the notebook the tick labels get chopped off, or encroach the plot top plot row. example below.
If in the layout object you set autosize=False
, start adjusting width and height, and set the domain of each YAxis object you can improve on things. But it is hard to get everything to fit and still have a decently sized plot area. It seems like things always get chopped off bottom and this is only 2 rows of plots. I can't see right now how to get things to scale to more rows.
import plotly.plotly as py
from plotly.graph_objs import *
trace1 = Scatter(
x=["A,4.0,AS-15-8045,830,lot45", "A,5.0,AS-15-8045,830,lot45", "A,6.0,AS-15-`8045,830,lot45"],
y=[4, 5, 6],xaxis='x1',yaxis='y1',name='A series set'
)
trace3 = Scatter(
x=["B,4.0,AS-15-8045,830,lot03", "B,5.0,AS-15-8045,830,lot04", "B,6.0,AS-15-8045,830,lot05"],
y=[600, 700, 800],xaxis='x3',yaxis='y3',name='B series dataset'
)
trace2 = Scatter(x=[20, 30, 40],y=[50, 60, 70],xaxis='x2',yaxis='y2')
trace4 = Scatter(x=[4000, 5000, 6000],y=[7000, 8000, 9000],xaxis='x4',yaxis='y4')
data = Data([trace1, trace2, trace3, trace4])
layout = Layout(
xaxis1 = XAxis(domain=[0, 0.45],anchor='y1',title='x1'),
yaxis1 = YAxis(domain=[0, 0.45],anchor='x1',title='y1'),
xaxis2 = XAxis(domain=[0.55, 1],anchor='y2',title='x2'),
yaxis2 = YAxis(domain=[0, 0.45],anchor='x2',title='y2'),
xaxis3 = XAxis(domain=[0, 0.45],anchor='y3',title='x3'),
yaxis3 = YAxis(domain=[0.55, 1],anchor='x3',title='y3'),
xaxis4 = XAxis(domain=[0.55, 1],anchor='y4',title='x4'),
yaxis4 = YAxis(domain=[0.55, 1],anchor='x4',title='y4')
)
fig = Figure(data=data, layout=layout)
py.iplot(fig)
Upvotes: 1
Views: 1748
Reputation: 5011
You can also use the width
and height
kwargs in py.iplot
directly.
Here is an example from our user guide.
Upvotes: 0
Reputation: 957
Disclaimer, I work for Plotly.
I just created an issue for it on our GitHub page: https://github.com/plotly/python-api/issues/218
For now, I was able to from IPython.display import IFrame
and display the plot in a new cell with IFrame(src=your_url, width=your_width, height=your_height)
.
Does that work for you for now? I'll drop a gist in the comments showing what I tried below.
Upvotes: 2