Last active
September 3, 2020 18:58
-
-
Save korakot/d357f5f3cbe11e6edcd2d5b59c808d41 to your computer and use it in GitHub Desktop.
using plotly (and other JS) with colab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly | |
plotly.io.renderers.default = 'colab' | |
# example | |
import plotly.graph_objects as go | |
fig = go.Figure( go.Scatter(x=[1,2,3], y=[1,3,2] ) ) | |
fig.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# colab.research.google.com/notebook#fileId=14oudHx5e5r7hm1QcbZ24FVHXgVPD0k8f | |
def configure_plotly_browser_state(): | |
import IPython | |
display(IPython.core.display.HTML(''' | |
<script src="/static/components/requirejs/require.js"></script> | |
<script> | |
requirejs.config({ | |
paths: { | |
base: '/static/base', | |
plotly: 'https://cdn.plot.ly/plotly-1.5.1.min.js?noext', | |
}, | |
}); | |
</script> | |
''')) | |
# then call it in every cell (each is an iframe) | |
configure_plotly_browser_state() | |
init_notebook_mode(connected=False) | |
x = np.random.randn(2000) | |
y = np.random.randn(2000) | |
iplot([Histogram2dContour(x=x, y=y, contours=Contours(coloring='heatmap')), | |
Scatter(x=x, y=y, mode='markers', | |
marker=Marker(color='white', size=3, opacity=0.3))], | |
show_link=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment