{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Comparing Scatter Plots with 75,000 Random Points"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now in Ploty you can implement WebGL with `Scattergl()` in place of `Scatter()`
\n",
"for increased speed, improved interactivity, and the ability to plot even more data!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### WebGL"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"N = 75000\n",
"trace = go.Scattergl(\n",
" x = np.random.randn(N),\n",
" y = np.random.randn(N),\n",
" mode = 'markers',\n",
" marker = dict(\n",
" line = dict(\n",
" width = 1, \n",
" color = '#404040')\n",
" )\n",
")\n",
"data = [trace]\n",
"layout = dict(title = 'WEBGL')\n",
"fig = dict(data=data, layout=layout)\n",
"py.iplot(data, filename='webgl75')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### SVG"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/plotly/plotly.py:236: UserWarning:\n",
"\n",
"Woah there! Look at all those points! Due to browser limitations, the Plotly SVG drawing functions have a hard time graphing more than 500k data points for line charts, or 40k points for other types of charts. Here are some suggestions:\n",
"(1) Use the `plotly.graph_objs.Scattergl` trace object to generate a WebGl graph.\n",
"(2) Trying using the image API to return an image instead of a graph URL\n",
"(3) Use matplotlib\n",
"(4) See if you can create your visualization with fewer data points\n",
"\n",
"If the visualization you're using aggregates points (e.g., box plot, histogram, etc.) you can disregard this warning.\n",
"\n",
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/plotly/plotly.py:1441: UserWarning:\n",
"\n",
"Estimated Draw Time Too Long\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"The draw time for this plot will be slow for all clients.\n"
]
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go\n",
"\n",
"import numpy as np\n",
"\n",
"N = 75000\n",
"trace = go.Scatter(\n",
" x = np.random.randn(N),\n",
" y = np.random.randn(N),\n",
" mode = 'markers',\n",
" marker = dict(\n",
" line = dict(\n",
" width = 1, \n",
" color = '#404040')\n",
" )\n",
")\n",
"data = [trace]\n",
"layout = dict(title = 'SVG')\n",
"fig = dict(data=data, layout=layout)\n",
"py.iplot(fig, filename='svg75')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### References"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For more information see
\n",
"`Scattergl()` : https://plotly.com/python/reference/#scattergl
\n",
"`Scatter()` : https://plotly.com/python/reference/#scatter"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting git+https://github.com/plotly/publisher.git\n",
" Cloning https://github.com/plotly/publisher.git to /var/folders/72/g6h98xwx0h1gp4kc8rzhsdh80000gn/T/pip-1gqcFV-build\n",
"Installing collected packages: publisher\n",
" Found existing installation: publisher 0.10\n",
" Uninstalling publisher-0.10:\n",
" Successfully uninstalled publisher-0.10\n",
" Running setup.py install for publisher ... \u001b[?25l-\b \bdone\n",
"\u001b[?25hSuccessfully installed publisher-0.10\n",
"\u001b[33mYou are using pip version 8.0.3, however version 8.1.2 is available.\n",
"You should consider upgrading via the 'pip install --upgrade pip' command.\u001b[0m\n"
]
}
],
"source": [
"from IPython.display import display, HTML\n",
"\n",
"display(HTML(''))\n",
"display(HTML(''))\n",
"\n",
"! pip install git+https://github.com/plotly/publisher.git --upgrade\n",
"import publisher\n",
"publisher.publish(\n",
" 'comparewebgl.ipynb', 'python/compare-webgl-svg/', 'Python Comparing WebGL vs SVG | plotly',\n",
" 'Comparing WebGL with Scattergl() to SVG with Scatter() in Python with Plotly.',\n",
" title = 'Comparing WebGL vs SVG | plotly',\n",
" name = 'Comparing WebGL vs SVG',\n",
" language='python')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}