I've seen zeppelin-plotly but it seems too complicated. The other things that worries me is that it involves modifying zeppelin's .war
file and I don't want to break things by error.
Is there another way to use Plotly with Zeppelin?
Figured it out using the %angular
interpreter feature. Here are the full steps to get it working
%sh pip install plotly
You can also do this on the terminal if you have access to it
def plot(plot_dic, height=500, width=500, **kwargs):
kwargs['output_type'] = 'div'
plot_str = plotly.offline.plot(plot_dic, **kwargs)
print('%%angular <div style="height: %ipx; width: %spx"> %s </div>' % (height, width, plot_str))
This custom plot funtion uses the angular interpreter to plot html. It take the same parameters as plotly.offline.plot
plus some extra parameters for the div's dimensions (I had bad results without these). Use it as you normally would use plotly.offline.plot
.
These plots are interactive! You don't need iplot
, the plot
function defined here works for 3D interactive plots as well.
%pyspark
import plotly
from plotly.graph_objs import Scatter, Layout
def plot(plot_dic, height=500, width=500, **kwargs):
kwargs['output_type'] = 'div'
plot_str = plotly.offline.plot(plot_dic, **kwargs)
print('%%angular <div style="height: %ipx; width: %spx"> %s </div>' % (height, width, plot_str))
plot({
"data": [
Scatter(x=[1, 2, 3, 4], y=[4, 5, 3, 7])
],
"layout": Layout(
title="hello world"
)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With