diff --git a/_posts/matplotlib/line_and_scatter/2015-04-09-line_and_scatter_matplotlib_index.html b/_posts/matplotlib/line_and_scatter/2015-04-09-line_and_scatter_matplotlib_index.html deleted file mode 100755 index f27ce7d5f487..000000000000 --- a/_posts/matplotlib/line_and_scatter/2015-04-09-line_and_scatter_matplotlib_index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: matplotlib Line and Scatter Plots | Examples | Plotly -name: Line and Scatter Plots -permalink: matplotlib/line-and-scatter/ -description: How to make line and scatter plots in matplotlib. Seven examples of basic and colored line and scatter plots. -layout: base -thumbnail: thumbnail/line-and-scatter.jpg -language: matplotlib -page_type: example_index -has_thumbnail: true -display_as: basic ---- -{% assign examples = site.posts | where:"language","matplotlib" | where:"suite","line_and_scatter" | sort: "order" %} -{% include auto_examples.html examples=examples %} diff --git a/_posts/matplotlib/line_and_scatter/2015-04-09-mpl-line-scatter.html b/_posts/matplotlib/line_and_scatter/2015-04-09-mpl-line-scatter.html deleted file mode 100755 index 1d72cb372726..000000000000 --- a/_posts/matplotlib/line_and_scatter/2015-04-09-mpl-line-scatter.html +++ /dev/null @@ -1,23 +0,0 @@ ---- -name: Line and Scatter Plot -plot_url: https://plot.ly/~PlotBot/94 -arrangement: horizontal -language: matplotlib -suite: line_and_scatter -order: 9 -sitemap: false ---- -import matplotlib.pyplot as plt - -import plotly.plotly as py -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -x = [1,2,3,4] -y = [3,4,8,6] - -plt.plot(x, 'o') -plt.plot(y) -fig = plt.gcf() - -plot_url = py.plot_mpl(fig, filename='mpl-line-scatter') diff --git a/_posts/matplotlib/line_and_scatter/2015-04-09-mpl-line-style.html b/_posts/matplotlib/line_and_scatter/2015-04-09-mpl-line-style.html deleted file mode 100755 index fd3e1ea68545..000000000000 --- a/_posts/matplotlib/line_and_scatter/2015-04-09-mpl-line-style.html +++ /dev/null @@ -1,24 +0,0 @@ ---- -name: Colored Matplotlib Line Chart -plot_url: https://plot.ly/~PlotBot/93 -arrangement: horizontal -language: matplotlib -suite: line_and_scatter -order: 9 -sitemap: false ---- -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -# evenly sampled time at 200ms intervals -t = np.arange(0., 5., 0.2) - -# red dashes, blue squares and green triangles -plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') - -fig = plt.gcf() -plot_url = py.plot_mpl(fig, filename='mpl-line-style') diff --git a/_posts/matplotlib/line_and_scatter/2015-06-30-line_and_scatter.html b/_posts/matplotlib/line_and_scatter/2015-06-30-line_and_scatter.html new file mode 100644 index 000000000000..c0486c8c044f --- /dev/null +++ b/_posts/matplotlib/line_and_scatter/2015-06-30-line_and_scatter.html @@ -0,0 +1,542 @@ +--- +permalink: matplotlib/line-and-scatter/ +description: How to make line and scatter plots in matplotlib. +name: Line and Scatter Plots +has_thumbnail: true +thumbnail: thumbnail/line-and-scatter.jpg +layout: user-guide +language: matplotlib +title: Line and Scatter Plots | Plotly +display_as: basic +has_thumbnail: true +ipynb: ~notebook_demo/243 +page_type: example_index +--- +{% raw %} +
+
+
+
+

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +
You can set up Plotly to work in online or offline mode, or in jupyter notebooks. +
We also have a quick-reference cheatsheet (new!) to help you get started!

+ +
+
+
+
+
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+
+
+
+
+
In [1]:
+
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[1]:
+ + + + +
+
'3.1.1'
+
+ +
+ +
+
+ +
+
+
+
+
+

Basic Scatter Plot

+
+
+
+
+
+
In [2]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+fig, ax = plt.subplots()
+ax.scatter(np.linspace(-1, 1, 50), np.random.randn(50))
+
+plotly_fig = tls.mpl_to_plotly(fig)
+py.iplot(plotly_fig, filename = 'mpl-basic-scatter-plot')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[2]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Line and Scatter Plot

+
+
+
+
+
+
In [3]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+
+x = [1,2,3,4]
+y = [3,4,8,6]
+
+plt.plot(x, 'o')
+plt.plot(y)
+fig = plt.gcf()
+
+plotly_fig = tls.mpl_to_plotly(fig)
+py.iplot(plotly_fig, filename = 'mpl-scatter-line')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[3]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Adding Line To Matplotlib Scatter Plot

Inspired From Stack Overflow

+ +
+
+
+
+
+
In [4]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+line = plt.figure()
+
+np.random.seed(5)
+x = np.arange(1, 101)
+y = 20 + 3 * x + np.random.normal(0, 60, 100)
+plt.plot(x, y, "o")
+
+
+# draw vertical line from (70,100) to (70, 250)
+plt.plot([70, 70], [100, 250], 'k-', lw=2)
+
+# draw diagonal line from (70, 90) to (90, 200)
+plt.plot([70, 90], [90, 200], 'k-')
+plotly_fig = tls.mpl_to_plotly(line)
+py.iplot(plotly_fig, filename = 'mpl-add-line-plot')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[4]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Matplotlib Scatter Colors And Symbols

+
+
+
+
+
+
In [5]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+fig, ax = plt.subplots()
+num = 1000
+s = 121
+x1 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num))
+y1 = np.linspace(-5,5,num) + (0.5 - np.random.rand(num))
+x2 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num))
+y2 = np.linspace(5,-5,num) + (0.5 - np.random.rand(num))
+x3 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num))
+y3 = (0.5 - np.random.rand(num))
+ax.scatter(x1, y1, color='r', s=2*s, marker='^', alpha=.4)
+ax.scatter(x2, y2, color='b', s=s/2, alpha=.4)
+ax.scatter(x3, y3, color='g', s=s/3, marker='s', alpha=.4)
+
+plotly_fig = tls.mpl_to_plotly(fig)
+py.iplot(plotly_fig, filename = 'mpl-scatter-color-symbol')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[5]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Scatter Plot With Duplicate Points

Inspired From Stack Overflow

+ +
+
+
+
+
+
In [6]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+alpha = plt.figure()
+
+data = [i for i in range(8) for j in range(np.random.randint(10))]
+x, y = np.array(data), np.array(data)
+plt.scatter(x, y, alpha=.1, s=400)
+
+plotly_fig = tls.mpl_to_plotly(alpha)
+py.iplot(plotly_fig, filename = 'mpl-duplicate-points')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[6]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Color And Marker Options

Inspired From Stack Overflow

+ +
+
+
+
+
+
In [7]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+from pylab import *
+import numpy as np
+
+scatter = plt.figure()
+
+colors = (i + j for j in 'o<.' for i in 'bgrcmyk')
+labels = 'one two three four five six seven eight nine ten'.split()
+x = linspace(0, 2*pi, 3000)
+d = (2+random((2,3000))) * c_[sin(x), cos(x)].T
+lg = []
+for i, l, c  in zip(range(10), labels, colors):
+    start, stop = i * 300, (i + 1) * 300
+    handle = plot(d[0, start:stop], d[1, start:stop], c, label=l)
+    lg.append(handle)
+
+plotly_fig = tls.mpl_to_plotly(scatter)
+py.iplot(plotly_fig, filename = 'mpl-color-marker-optns')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[7]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Scatter Plot With Legend And Label

Inspired From Stack Overflow

+ +
+
+
+
+
+
In [8]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+colors = ['b', 'c', 'y', 'm', 'r']
+
+lo = plt.scatter(random(10), random(10), marker='x', color=colors[0])
+ll = plt.scatter(random(10), random(10), marker='o', color=colors[0])
+l  = plt.scatter(random(10), random(10), marker='o', color=colors[1])
+a  = plt.scatter(random(10), random(10), marker='o', color=colors[2])
+h  = plt.scatter(random(10), random(10), marker='o', color=colors[3])
+hh = plt.scatter(random(10), random(10), marker='o', color=colors[4])
+ho = plt.scatter(random(10), random(10), marker='x', color=colors[4])
+
+text = iter(['Low Outlier', 'LoLo', 'Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'])
+
+
+mpl_fig = plt.gcf()
+plotly_fig = tls.mpl_to_plotly( mpl_fig )
+
+for dat in plotly_fig['data']:
+    t = text.next()
+    dat.update({'name': t, 'text':t})
+
+plotly_fig['layout']['showlegend'] = True
+py.iplot(plotly_fig, filename = 'mpl-scatter-legend-label')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[8]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Colored Matplotlib Line Chart

+
+
+
+
+
+
In [9]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+# evenly sampled time at 200ms intervals
+t = np.arange(0., 5., 0.2)
+
+# red dashes, blue squares and green triangles
+plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
+
+fig = plt.gcf()
+plotly_fig = tls.mpl_to_plotly(fig)
+py.iplot(plotly_fig, filename = 'mpl-colored-line')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[9]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Reference

See https://plot.ly/python/reference/ for more information and chart attribute options!

+ +
+
+
+ + +{% endraw %} \ No newline at end of file diff --git a/_posts/matplotlib/line_and_scatter/line_and_scatter.ipynb b/_posts/matplotlib/line_and_scatter/line_and_scatter.ipynb new file mode 100644 index 000000000000..4fd7c3b5e02e --- /dev/null +++ b/_posts/matplotlib/line_and_scatter/line_and_scatter.ipynb @@ -0,0 +1,526 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### New to Plotly?\n", + "Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n", + "
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).\n", + "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.1.1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Basic Scatter Plot" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig, ax = plt.subplots()\n", + "ax.scatter(np.linspace(-1, 1, 50), np.random.randn(50))\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(fig)\n", + "py.iplot(plotly_fig, filename = 'mpl-basic-scatter-plot')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Line and Scatter Plot" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "\n", + "x = [1,2,3,4]\n", + "y = [3,4,8,6]\n", + "\n", + "plt.plot(x, 'o')\n", + "plt.plot(y)\n", + "fig = plt.gcf()\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(fig)\n", + "py.iplot(plotly_fig, filename = 'mpl-scatter-line')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Adding Line To Matplotlib Scatter Plot\n", + "Inspired From [Stack Overflow](https://stackoverflow.com/questions/12864294/adding-an-arbitrary-line-to-a-matplotlib-plot-in-ipython-notebook)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "line = plt.figure()\n", + "\n", + "np.random.seed(5)\n", + "x = np.arange(1, 101)\n", + "y = 20 + 3 * x + np.random.normal(0, 60, 100)\n", + "plt.plot(x, y, \"o\")\n", + "\n", + "\n", + "# draw vertical line from (70,100) to (70, 250)\n", + "plt.plot([70, 70], [100, 250], 'k-', lw=2)\n", + "\n", + "# draw diagonal line from (70, 90) to (90, 200)\n", + "plt.plot([70, 90], [90, 200], 'k-')\n", + "plotly_fig = tls.mpl_to_plotly(line)\n", + "py.iplot(plotly_fig, filename = 'mpl-add-line-plot')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Matplotlib Scatter Colors And Symbols" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig, ax = plt.subplots()\n", + "num = 1000\n", + "s = 121\n", + "x1 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num))\n", + "y1 = np.linspace(-5,5,num) + (0.5 - np.random.rand(num))\n", + "x2 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num))\n", + "y2 = np.linspace(5,-5,num) + (0.5 - np.random.rand(num))\n", + "x3 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num))\n", + "y3 = (0.5 - np.random.rand(num))\n", + "ax.scatter(x1, y1, color='r', s=2*s, marker='^', alpha=.4)\n", + "ax.scatter(x2, y2, color='b', s=s/2, alpha=.4)\n", + "ax.scatter(x3, y3, color='g', s=s/3, marker='s', alpha=.4)\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(fig)\n", + "py.iplot(plotly_fig, filename = 'mpl-scatter-color-symbol')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Scatter Plot With Duplicate Points\n", + "Inspired From [Stack Overflow](https://stackoverflow.com/questions/21081453/drawing-scatter-graph-using-matlibplot-pyplot-when-points-are-duplicate)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "alpha = plt.figure()\n", + "\n", + "data = [i for i in range(8) for j in range(np.random.randint(10))]\n", + "x, y = np.array(data), np.array(data)\n", + "plt.scatter(x, y, alpha=.1, s=400)\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(alpha)\n", + "py.iplot(plotly_fig, filename = 'mpl-duplicate-points')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Color And Marker Options\n", + "Inspired From [Stack Overflow](https://stackoverflow.com/questions/872397/matplotlib-legend-not-displayed-properly)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "from pylab import *\n", + "import numpy as np\n", + "\n", + "scatter = plt.figure()\n", + "\n", + "colors = (i + j for j in 'o<.' for i in 'bgrcmyk')\n", + "labels = 'one two three four five six seven eight nine ten'.split()\n", + "x = linspace(0, 2*pi, 3000)\n", + "d = (2+random((2,3000))) * c_[sin(x), cos(x)].T\n", + "lg = []\n", + "for i, l, c in zip(range(10), labels, colors):\n", + " start, stop = i * 300, (i + 1) * 300\n", + " handle = plot(d[0, start:stop], d[1, start:stop], c, label=l)\n", + " lg.append(handle)\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(scatter)\n", + "py.iplot(plotly_fig, filename = 'mpl-color-marker-optns')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Scatter Plot With Legend And Label\n", + "Inspired From [Stack Overflow](https://stackoverflow.com/questions/17411940/matplotlib-scatter-plot-legend)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "colors = ['b', 'c', 'y', 'm', 'r']\n", + "\n", + "lo = plt.scatter(random(10), random(10), marker='x', color=colors[0])\n", + "ll = plt.scatter(random(10), random(10), marker='o', color=colors[0])\n", + "l = plt.scatter(random(10), random(10), marker='o', color=colors[1])\n", + "a = plt.scatter(random(10), random(10), marker='o', color=colors[2])\n", + "h = plt.scatter(random(10), random(10), marker='o', color=colors[3])\n", + "hh = plt.scatter(random(10), random(10), marker='o', color=colors[4])\n", + "ho = plt.scatter(random(10), random(10), marker='x', color=colors[4])\n", + "\n", + "text = iter(['Low Outlier', 'LoLo', 'Lo', 'Average', 'Hi', 'HiHi', 'High Outlier'])\n", + "\n", + "\n", + "mpl_fig = plt.gcf()\n", + "plotly_fig = tls.mpl_to_plotly( mpl_fig )\n", + "\n", + "for dat in plotly_fig['data']:\n", + " t = text.next()\n", + " dat.update({'name': t, 'text':t})\n", + "\n", + "plotly_fig['layout']['showlegend'] = True\n", + "py.iplot(plotly_fig, filename = 'mpl-scatter-legend-label')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Colored Matplotlib Line Chart" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "# evenly sampled time at 200ms intervals\n", + "t = np.arange(0., 5., 0.2)\n", + "\n", + "# red dashes, blue squares and green triangles\n", + "plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')\n", + "\n", + "fig = plt.gcf()\n", + "plotly_fig = tls.mpl_to_plotly(fig)\n", + "py.iplot(plotly_fig, filename = 'mpl-colored-line')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Reference\n", + "See https://plot.ly/python/reference/ for more information and chart attribute options!" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "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 c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-3uz0hj\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-r84gmb\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", + "Installing collected packages: publisher\n", + " Found existing installation: publisher 0.11\n", + " Uninstalling publisher-0.11:\n", + " Successfully uninstalled publisher-0.11\n", + "Successfully installed publisher-0.11\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", + " 'line_and_scatter.ipynb', 'matplotlib/line-and-scatter/', 'Line and Scatter Plots',\n", + " 'How to make line and scatter plots in matplotlib.',\n", + " title = 'Line and Scatter Plots | Plotly',\n", + " has_thumbnail='true', thumbnail='thumbnail/line-and-scatter.jpg',\n", + " language='matplotlib',\n", + " page_type='example_index',\n", + " display_as='basic', ipynb='~notebook_demo/243')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_posts/matplotlib/line_exclusive/2015-04-09-line_exclusive_matplotlib_index.html b/_posts/matplotlib/line_exclusive/2015-04-09-line_exclusive_matplotlib_index.html deleted file mode 100755 index 15aeb5859ba1..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-04-09-line_exclusive_matplotlib_index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: matplotlib Line Charts | Examples | Plotly -name: plot | Line Charts -permalink: matplotlib/plot/ -description: How to make a plot in matplotlib. Examples of the plot function, line and marker types, custom colors, and log and semi-log axes. -layout: base -thumbnail: thumbnail/line_exclusive.jpg -language: matplotlib -page_type: example_index -has_thumbnail: true -display_as: chart_type ---- -{% assign examples = site.posts | where:"language","matplotlib" | where:"suite","line_exclusive" | sort: "order" %} -{% include auto_examples.html examples=examples %} diff --git a/_posts/matplotlib/line_exclusive/2015-04-09-mpl-basic-line.html b/_posts/matplotlib/line_exclusive/2015-04-09-mpl-basic-line.html deleted file mode 100755 index bee2cd6e7b0e..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-04-09-mpl-basic-line.html +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Matplotlib basic Line Chart Example with Legend -plot_url: https://plot.ly/~tarzzz/1980 -arrangement: horizontal -language: matplotlib -suite: line_exclusive -order: 1 -sitemap: false ---- -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -x = np.linspace(0, 10) -plt.plot(x, np.sin(x), '--', linewidth=2) -plt.plot(x, np.cos(x), '--', linewidth=2) - -fig = plt.gcf() - -plotly_fig = tls.mpl_to_plotly(fig) -plotly_fig['layout']['showlegend'] = True - -fig = plt.gcf() -plot_url = py.plot_mpl(fig, filename='mpl-basic-line') diff --git a/_posts/matplotlib/line_exclusive/2015-06-30-line_exclusive.html b/_posts/matplotlib/line_exclusive/2015-06-30-line_exclusive.html new file mode 100644 index 000000000000..916fd801425f --- /dev/null +++ b/_posts/matplotlib/line_exclusive/2015-06-30-line_exclusive.html @@ -0,0 +1,329 @@ +--- +permalink: matplotlib/plot/ +description: How to make a plot in matplotlib. Examples of the plot function, line and marker types, custom colors, and log and semi-log axes. +name: Line Charts +has_thumbnail: true +thumbnail: thumbnail/line_exclusive.jpg +layout: user-guide +language: matplotlib +title: Line Charts | Plotly +display_as: basic +has_thumbnail: true +ipynb: ~notebook_demo/241 +page_type: example_index +--- +{% raw %} +
+
+
+
+

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +
You can set up Plotly to work in online or offline mode, or in jupyter notebooks. +
We also have a quick-reference cheatsheet (new!) to help you get started!

+

IF you're adding a doc about a new feature, the second and third cells will display a version check. This is to ensure the

+ +
+
+
+
+
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+
+
+
+
+
In [1]:
+
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[1]:
+ + + + +
+
'3.1.1'
+
+ +
+ +
+
+ +
+
+
+
+
+

Matplotlib basic Line Chart Example with Legend

+
+
+
+
+
+
In [ ]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+x = np.linspace(0, 10)
+plt.plot(x, np.sin(x), '--', linewidth=2)
+plt.plot(x, np.cos(x), '--', linewidth=2)
+
+fig = plt.gcf()
+
+plotly_fig = tls.mpl_to_plotly(fig)
+plotly_fig['layout']['showlegend'] = True
+
+fig = plt.gcf()
+py.iplot(plotly_fig)
+
+ +
+
+
+ +
+
+
+
+
+

Different colored lines for different plots

Inspired by Stack Overflow

+ +
+
+
+
+
+
In [ ]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+colormaps_fig = plt.figure()
+
+num_plots = 10
+
+# Have a look at the colormaps here and decide which one you'd like:
+# http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html
+colormap = plt.cm.gist_ncar
+plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, num_plots)])
+
+# Plot several different functions...
+x = np.arange(10)
+labels = []
+for i in range(1, num_plots + 1):
+    plt.plot(x, i * x + 5 * i)
+    labels.append(r'$y = %ix + %i$' % (i, 5*i))
+
+plotly_fig = tls.mpl_to_plotly(colormaps_fig)
+py.iplot(plotly_fig)
+
+ +
+
+
+ +
+
+
+
+
+

Sine and Cosine graph

Inspired by Stack Overflow

+ +
+
+
+
+
+
In [ ]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import pylab
+import numpy as np
+
+
+legend_fig = plt.figure()
+
+x = np.linspace(0, 20, 1000)
+y1 = np.sin(x)
+y2 = np.cos(x)
+
+pylab.plot(x, y1, '-b', label='sine')
+pylab.plot(x, y2, '-r', label='cosine')
+pylab.ylim(-1.5, 2.0)
+
+plotly_fig = tls.mpl_to_plotly(legend_fig)
+py.iplot(plotly_fig)
+
+ +
+
+
+ +
+
+
+
+
+

Density plot

Inspired by Stack Overflow

+ +
+
+
+
+
+
In [ ]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+from scipy.stats import gaussian_kde
+
+mpl_density = plt.figure()
+
+data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8
+density = gaussian_kde(data)
+xs = np.linspace(0,8,200)
+density.covariance_factor = lambda : .25
+density._compute_covariance()
+plt.plot(xs,density(xs))
+
+plotly_fig = tls.mpl_to_plotly(mpl_density)
+py.iplot(plotly_fig)
+
+ +
+
+
+ +
+
+
+
+
+

Logarithmic axes

Inspired by Stack Overflow

+ +
+
+
+
+
+
In [ ]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+from matplotlib import pyplot
+import numpy as np
+
+x = np.arange(0.01,50,0.1)
+
+fig,(ax1,ax2) = plt.subplots(2)
+
+ax1.plot(x,np.exp(50+x/50.))
+ax1.set_xlim(x[-1],x[0])
+ax1.set_title('plot')
+
+ax2.semilogx(x,np.log(100*x))
+ax2.set_xlim(x[-1],x[0])
+
+plotly_fig = tls.mpl_to_plotly(fig)
+py.iplot(plotly_fig)
+
+ +
+
+
+ +
+
+
+
+
+

Matplotlib Colormap

Inspired by Stack Overflow

+ +
+
+
+
+
+
In [ ]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib as mpl
+import matplotlib.pyplot as plt
+import numpy as np
+
+mpl_color = plt.figure()
+
+# Generate data...
+nx, nsteps = 100, 20
+x = np.linspace(0, 1, nx)
+data = np.random.random((nx, nsteps)) - 0.5
+data = data.cumsum(axis=0)
+data = data.cumsum(axis=1)
+
+# Plot
+cmap = mpl.cm.autumn
+for i, y in enumerate(data.T):
+    plt.plot(x, y, color=cmap(i / float(nsteps)))
+
+plotly_fig = tls.mpl_to_plotly(mpl_color)
+py.iplot(plotly_fig)
+
+ +
+
+
+ +
+
+
+
+
+

Reference

See https://plot.ly/python/reference/ for more information and chart attribute options!

+ +
+
+
+ + +{% endraw %} \ No newline at end of file diff --git a/_posts/matplotlib/line_exclusive/2015-07-14-colored-lines.html b/_posts/matplotlib/line_exclusive/2015-07-14-colored-lines.html deleted file mode 100644 index ba844cba4875..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-07-14-colored-lines.html +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: different colored lines for different plots -plot_url: https://plot.ly/~MattSundquist/19306/-line0-line1-line2-line3-line4-line5-line6-line7-line8-line9/ -arrangement: horizontal -language: matplotlib -suite: line_exclusive -description: Inspired by Stack Overflow. -order: 2 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import matplotlib.pyplot as plt -import numpy as np -import plotly.plotly as py - -colormaps_fig = plt.figure() - -num_plots = 10 - -# Have a look at the colormaps here and decide which one you'd like: -# http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html -colormap = plt.cm.gist_ncar -plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, num_plots)]) - -# Plot several different functions... -x = np.arange(10) -labels = [] -for i in range(1, num_plots + 1): - plt.plot(x, i * x + 5 * i) - labels.append(r'$y = %ix + %i$' % (i, 5*i)) - -plot_url = py.plot_mpl(colormaps_fig, filename='mpl-colormaps') diff --git a/_posts/matplotlib/line_exclusive/2015-07-14-density-plot.html b/_posts/matplotlib/line_exclusive/2015-07-14-density-plot.html deleted file mode 100644 index a87c5b7a669f..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-07-14-density-plot.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -name: how to create a density plot -plot_url: https://plot.ly/~MattSundquist/19269/-line0/ -arrangement: horizontal -language: matplotlib -suite: line_exclusive -order: 3 -description: Inspired by Stack Overflow. -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import plotly.plotly as py -import matplotlib.pyplot as plt -import numpy as np -from scipy.stats import gaussian_kde - -mpl_density = plt.figure() - -data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8 -density = gaussian_kde(data) -xs = np.linspace(0,8,200) -density.covariance_factor = lambda : .25 -density._compute_covariance() -plt.plot(xs,density(xs)) - -plot_url = py.plot_mpl(mpl_density, filename='mpl-density') diff --git a/_posts/matplotlib/line_exclusive/2015-08-14-logarithmic.html b/_posts/matplotlib/line_exclusive/2015-08-14-logarithmic.html deleted file mode 100644 index fc0f2affd48f..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-08-14-logarithmic.html +++ /dev/null @@ -1,28 +0,0 @@ ---- -name: logarithmic axes in Python -plot_url: https://plot.ly/~MattSundquist/19281/-line0/ -arrangement: horizontal -language: matplotlib -suite: line_exclusive -description: Inspired by Stack Overflow. -order: 4 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import matplotlib.pyplot as plt -from matplotlib import pyplot -import plotly.plotly as py - -log_fig = plt.figure() - -a = [ pow(10,i) for i in range(10) ] - -pyplot.subplot(2,1,1) -pyplot.plot(a, color='blue', lw=2) -pyplot.yscale('log') -pyplot.show() - -plot_url = py.plot_mpl(log_fig, filename='mpl-log') diff --git a/_posts/matplotlib/line_exclusive/2015-08-14-sine-cosine.html b/_posts/matplotlib/line_exclusive/2015-08-14-sine-cosine.html deleted file mode 100644 index f152ef8357be..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-08-14-sine-cosine.html +++ /dev/null @@ -1,29 +0,0 @@ ---- -name: how to graph a sine and cosine -plot_url: https://plot.ly/~MattSundquist/19312/sine-vs-cosine/ -arrangement: horizontal -language: matplotlib -suite: line_exclusive -description: Inspired by Stack Overflow. -order: 3 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import numpy as np -import pylab -import plotly.plotly as py - -legend_fig = plt.figure() - -x = np.linspace(0, 20, 1000) -y1 = np.sin(x) -y2 = np.cos(x) - -pylab.plot(x, y1, '-b', label='sine') -pylab.plot(x, y2, '-r', label='cosine') -pylab.ylim(-1.5, 2.0) - -plot_url = py.plot_mpl(legend_fig, filename='mpl-sine-cosine') diff --git a/_posts/matplotlib/line_exclusive/2015-08-15-color-example.html b/_posts/matplotlib/line_exclusive/2015-08-15-color-example.html deleted file mode 100644 index f981646c3fc9..000000000000 --- a/_posts/matplotlib/line_exclusive/2015-08-15-color-example.html +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: example using Matplotlib Colormap -plot_url: https://plot.ly/~MattSundquist/19334/-line0-line1-line2-line3-line4-line5-line6-line7-line8-line9-line10-line11-line1/ -arrangement: horizontal -language: matplotlib -suite: line_exclusive -description: Inspired by Stack Overflow. -order: 6 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import matplotlib.pyplot as plt -import matplotlib as mpl -import numpy as np -import plotly.plotly as py - -mpl_color = plt.figure() - -# Generate data... -nx, nsteps = 100, 20 -x = np.linspace(0, 1, nx) -data = np.random.random((nx, nsteps)) - 0.5 -data = data.cumsum(axis=0) -data = data.cumsum(axis=1) - -# Plot -cmap = mpl.cm.autumn -for i, y in enumerate(data.T): - plt.plot(x, y, color=cmap(i / float(nsteps))) - -plot_url = py.plot_mpl(mpl_color, filename='mpl-color-example') diff --git a/_posts/matplotlib/line_exclusive/line_exclusive.ipynb b/_posts/matplotlib/line_exclusive/line_exclusive.ipynb new file mode 100644 index 000000000000..dab2f1852157 --- /dev/null +++ b/_posts/matplotlib/line_exclusive/line_exclusive.ipynb @@ -0,0 +1,448 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### New to Plotly?\n", + "Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n", + "
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).\n", + "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!\n", + "\n", + "IF you're adding a doc about a new feature, the second and third cells will display a version check. This is to ensure the " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.1.1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Matplotlib basic Line Chart Example with Legend" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "x = np.linspace(0, 10)\n", + "plt.plot(x, np.sin(x), '--', linewidth=2)\n", + "plt.plot(x, np.cos(x), '--', linewidth=2)\n", + "\n", + "fig = plt.gcf()\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(fig)\n", + "plotly_fig['layout']['showlegend'] = True\n", + "\n", + "fig = plt.gcf()\n", + "py.iplot(plotly_fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Different colored lines for different plots\n", + "Inspired by [Stack Overflow](http://stackoverflow.com/questions/4805048/how-to-get-different-colored-lines-for-different-plots-in-a-single-figure/4805456#4805456)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "colormaps_fig = plt.figure()\n", + "\n", + "num_plots = 10\n", + "\n", + "# Have a look at the colormaps here and decide which one you'd like:\n", + "# http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html\n", + "colormap = plt.cm.gist_ncar\n", + "plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, num_plots)])\n", + "\n", + "# Plot several different functions...\n", + "x = np.arange(10)\n", + "labels = []\n", + "for i in range(1, num_plots + 1):\n", + " plt.plot(x, i * x + 5 * i)\n", + " labels.append(r'$y = %ix + %i$' % (i, 5*i))\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(colormaps_fig)\n", + "py.iplot(plotly_fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Sine and Cosine graph\n", + "Inspired by [Stack Overflow](http://stackoverflow.com/questions/19125722/adding-a-legend-to-pyplot-in-matplotlib-in-the-most-simple-manner-possible)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import pylab\n", + "import numpy as np\n", + "\n", + "\n", + "legend_fig = plt.figure()\n", + "\n", + "x = np.linspace(0, 20, 1000)\n", + "y1 = np.sin(x)\n", + "y2 = np.cos(x)\n", + "\n", + "pylab.plot(x, y1, '-b', label='sine')\n", + "pylab.plot(x, y2, '-r', label='cosine')\n", + "pylab.ylim(-1.5, 2.0)\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(legend_fig)\n", + "py.iplot(plotly_fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Density plot\n", + "Inspired by [Stack Overflow](http://stackoverflow.com/questions/4150171/how-to-create-a-density-plot-in-matplotlib/4152016#4152016)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "from scipy.stats import gaussian_kde\n", + "\n", + "mpl_density = plt.figure()\n", + "\n", + "data = [1.5]*7 + [2.5]*2 + [3.5]*8 + [4.5]*3 + [5.5]*1 + [6.5]*8\n", + "density = gaussian_kde(data)\n", + "xs = np.linspace(0,8,200)\n", + "density.covariance_factor = lambda : .25\n", + "density._compute_covariance()\n", + "plt.plot(xs,density(xs))\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(mpl_density)\n", + "py.iplot(plotly_fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Logarithmic axes\n", + "Inspired by [Stack Overflow](https://stackoverflow.com/questions/35079291/using-a-logarithmic-scale-in-matplotlib)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "from matplotlib import pyplot\n", + "import numpy as np\n", + "\n", + "x = np.arange(0.01,50,0.1)\n", + "\n", + "fig,(ax1,ax2) = plt.subplots(2)\n", + "\n", + "ax1.plot(x,np.exp(50+x/50.))\n", + "ax1.set_xlim(x[-1],x[0])\n", + "ax1.set_title('plot')\n", + "\n", + "ax2.semilogx(x,np.log(100*x))\n", + "ax2.set_xlim(x[-1],x[0])\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(fig)\n", + "py.iplot(plotly_fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Matplotlib Colormap\n", + "Inspired by [Stack Overflow](http://stackoverflow.com/questions/9999010/can-i-put-a-color-changer-in-a-loop)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib as mpl\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "mpl_color = plt.figure()\n", + "\n", + "# Generate data...\n", + "nx, nsteps = 100, 20\n", + "x = np.linspace(0, 1, nx)\n", + "data = np.random.random((nx, nsteps)) - 0.5\n", + "data = data.cumsum(axis=0)\n", + "data = data.cumsum(axis=1)\n", + "\n", + "# Plot\n", + "cmap = mpl.cm.autumn\n", + "for i, y in enumerate(data.T):\n", + " plt.plot(x, y, color=cmap(i / float(nsteps)))\n", + "\n", + "plotly_fig = tls.mpl_to_plotly(mpl_color)\n", + "py.iplot(plotly_fig)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Reference\n", + "See https://plot.ly/python/reference/ for more information and chart attribute options!" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "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 c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-e0l3ts\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-mfzbyc\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", + "Installing collected packages: publisher\n", + " Found existing installation: publisher 0.11\n", + " Uninstalling publisher-0.11:\n", + " Successfully uninstalled publisher-0.11\n", + "Successfully installed publisher-0.11\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", + " 'line_exclusive.ipynb', 'matplotlib/plot/', 'Line Charts',\n", + " 'How to make a plot in matplotlib. Examples of the plot function, line and marker types, custom colors, and log and semi-log axes.',\n", + " title = 'Line Charts | Plotly',\n", + " has_thumbnail='true', thumbnail='thumbnail/line_exclusive.jpg',\n", + " language='matplotlib',\n", + " page_type='example_index',\n", + " display_as='basic', ipynb='~notebook_demo/241')\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_posts/matplotlib/lines-and-markers/2015-06-30-line-charts.html b/_posts/matplotlib/lines-and-markers/2015-06-30-line-charts.html new file mode 100644 index 000000000000..d7578c796498 --- /dev/null +++ b/_posts/matplotlib/lines-and-markers/2015-06-30-line-charts.html @@ -0,0 +1,460 @@ +--- +permalink: matplotlib/line-charts/ +description: Lines and markers options in matplotlib. Examples of different types of lines and markers available in matplotlib. +name: Lines and Markers +has_thumbnail: true +thumbnail: thumbnail/lines-and-markers.jpg +layout: user-guide +language: matplotlib +title: Lines and markers | Plotly +display_as: basic +has_thumbnail: true +ipynb: ~notebook_demo/234 +page_type: example_index +--- +{% raw %} +
+
+
+
+

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +
You can set up Plotly to work in online or offline mode, or in jupyter notebooks. +
We also have a quick-reference cheatsheet (new!) to help you get started!

+ +
+
+
+
+
+
+
+

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+ +
+
+
+
+
+
In [1]:
+
+
+
import plotly
+plotly.__version__
+
+ +
+
+
+ +
+
+ + +
+ +
Out[1]:
+ + + + +
+
'3.1.1'
+
+ +
+ +
+
+ +
+
+
+
+
+

Passing Line Styles As List

+
+
+
+
+
+
In [2]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+color = 'cornflowerblue'
+points = np.ones(5)  # Draw 5 points for each line
+text_style = dict(horizontalalignment='right', verticalalignment='center',
+                  fontsize=12, fontdict={'family': 'monospace'})
+
+
+def format_axes(ax):
+    ax.margins(0.2)
+    ax.set_axis_off()
+
+
+def nice_repr(text):
+    return repr(text).lstrip('u')
+
+
+# Plot all line styles.
+fig = plt.figure()
+ax1 = fig.add_subplot(221)
+ax2 = fig.add_subplot(222)
+ax3 = fig.add_subplot(223)
+ax4 = fig.add_subplot(224)
+
+linestyles = ['-', '--', '-.']
+y1 = 1
+ax1.plot(y1 * points, linestyle='-', color=color, linewidth=3)
+ax1.set_title('Line Type -')
+
+y2=2
+ax2.plot(y2 * points, linestyle='--', color=color, linewidth=3)
+ax2.set_title('Line Type --')
+
+y3=3
+ax3.plot(y3* points, linestyle='-.', color=color, linewidth=3)
+ax3.set_xlabel('Line Type -.')
+
+plotly_fig = tls.mpl_to_plotly( fig )
+py.iplot(plotly_fig, filename='mpl-linestyles')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[2]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Setting Linestyles Per Column In Pandas

Inspired From Pandas Docs

+ +
+
+
+
+
+
In [3]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+import pandas as pd
+
+x = np.linspace(-5,5,1000)
+sinx = np.sin(x)
+cosx = np.cos(x)
+logx = np.log(x)
+
+df = pd.DataFrame({'x':x, 'sinx':sinx, 'cosx':cosx, 'logx':logx})
+
+ax = df.plot(kind='line', style=['-', '--', '-.'], legend=False)
+ax.set_title('Setting Line Styles Per column in Matplotlib and pandas')
+fig = ax.get_figure()
+
+plotly_fig = tls.mpl_to_plotly( fig )
+plotly_fig['layout']['showlegend'] = True
+py.iplot(plotly_fig, filename='mpl-linestyles-column')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[3]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Cycling Through Various Line Styles

Inspired From Stack Overflow

+ +
+
+
+
+
+
In [4]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+from itertools import cycle
+
+lines = ["-","--","-."]
+linecycler = cycle(lines)
+fig = plt.figure()
+ax = fig.add_subplot(111)
+for i in range(10):
+    x = range(i,i+10)
+    ax.plot(range(10),x,next(linecycler))
+
+ax.set_title('Cycling through line styles in matplotlib')
+
+plotly_fig = tls.mpl_to_plotly( fig )
+py.iplot(plotly_fig, filename='mpl-cycle-linestyles')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[4]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Setting Marker Size In Matplotlib

Inspired From Stack Overflow

+ +
+
+
+
+
+
In [5]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+fig = plt.figure()
+ax = fig.add_subplot(111)
+
+x = [0,2,4,6,8,10]
+y = [0]*len(x)
+s = [100,  400, 490, 600, 240, 160] # Specifies marker size
+
+ax.scatter(x,y,s=s)
+ax.set_title('Plot with Different Marker size, matplotlib and plotly')
+
+plotly_fig = tls.mpl_to_plotly( fig )
+plotly_fig['layout']['showlegend'] = True
+py.iplot(plotly_fig, filename='mpl-marker-size')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[5]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Setting Marker Color In Matplotlib

+
+
+
+
+
+
In [6]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+fig = plt.figure()
+ax = fig.add_subplot(111)
+
+x = [0,2,4,6,8,10]
+y = [0]*len(x)
+c = 'gbrcyk'
+
+ax.scatter(x,y,s=400,c=c)
+ax.set_title('Plot with Different Marker Color, matplotlib and plotly')
+
+plotly_fig = tls.mpl_to_plotly( fig )
+py.iplot(plotly_fig, filename='mpl-marker-color')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[6]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Setting Marker Edge Color in matplotlib

+
+
+
+
+
+
In [7]:
+
+
+
import plotly.plotly as py
+import plotly.tools as tls
+
+import matplotlib.pyplot as plt
+import numpy as np
+
+fig = plt.figure()
+ax = fig.add_subplot(111)
+
+x = [0,2,4,6,8,10]
+y = [1]*len(x)
+marker_edge_color = 'rgbcyk'
+
+for i in range(6):
+    ax = fig.add_subplot(2,3,i+1)
+    ax.plot(x,y,marker='o', markersize=20, markerfacecolor='lightgrey',markeredgecolor=marker_edge_color[i])
+    ax.set_title('Edge Color: %s'%marker_edge_color[i])
+
+fig.tight_layout()
+plotly_fig = tls.mpl_to_plotly( fig )
+py.iplot(plotly_fig, filename='mpl-marker-edge')
+
+ +
+
+
+ +
+
+ + +
+ +
Out[7]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

Reference

See https://plot.ly/python/reference/ for more information and chart attribute options!

+ +
+
+
+ + +{% endraw %} \ No newline at end of file diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-line-style-cycle.html b/_posts/matplotlib/lines-and-markers/2016-02-08-line-style-cycle.html deleted file mode 100644 index a7b63ac92d23..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-line-style-cycle.html +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: Cycling through various line styles -plot_url: https://plot.ly/~tarzzz/1174 -arrangement: horizontal -language: matplotlib -suite: lines_and_markers -order: 3 -sitemap: false -description: Inspired from Stack Overflow ---- - -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -import plotly.tools as tls -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -from itertools import cycle - -lines = ["-","--","-.",":"] -linecycler = cycle(lines) -fig = plt.figure() -ax = fig.add_subplot(111) -for i in range(10): - x = range(i,i+10) - ax.plot(range(10),x,next(linecycler)) - -ax.set_title('Cycling through line styles in matplotlib') - -plotly_fig = tls.mpl_to_plotly( fig ) -plot_url = py.plot(plotly_fig, filename='mpl-linestyles-cycle') diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-line-styles-per-column.html b/_posts/matplotlib/lines-and-markers/2016-02-08-line-styles-per-column.html deleted file mode 100644 index 413ac4b060b2..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-line-styles-per-column.html +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: Setting Linestyles per column in Pandas -plot_url: https://plot.ly/~tarzzz/1180 -arrangement: horizontal -language: matplotlib -suite: lines_and_markers -order: 3 -sitemap: false -description: Inspired from Pandas Docs ---- - -import matplotlib.pyplot as plt -import numpy as np -import pandas as pd - -import plotly.plotly as py -import plotly.tools as tls -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -x = np.linspace(-5,5,1000) -sinx = np.sin(x) -cosx = np.cos(x) -logx = np.log(x) - -df = pd.DataFrame({'x':x, 'sinx':sinx, 'cosx':cosx, 'logx':logx}) - -ax = df.plot(kind='line', style=['-', '--', '-.'], legend=False) -ax.set_title('Setting Line Styles Per column in Matplotlib and pandas') -fig = ax.get_figure() - -plotly_fig = tls.mpl_to_plotly( fig ) -plotly_fig['layout']['showlegend'] = True -plotly_url = py.plot(plotly_fig, filename='mpl-linestyles-per-column') diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-line-styles.html b/_posts/matplotlib/lines-and-markers/2016-02-08-line-styles.html deleted file mode 100644 index 5484f22f4e2c..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-line-styles.html +++ /dev/null @@ -1,61 +0,0 @@ ---- -name: Passing Line Styles as a List -plot_url: https://plot.ly/~tarzzz/1210 -arrangement: horizontal -language: matplotlib -suite: lines_and_markers -order: 1 -sitemap: false ---- - -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -import plotly.tools as tls -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - - - -color = 'cornflowerblue' -points = np.ones(5) # Draw 5 points for each line -text_style = dict(horizontalalignment='right', verticalalignment='center', - fontsize=12, fontdict={'family': 'monospace'}) - - -def format_axes(ax): - ax.margins(0.2) - ax.set_axis_off() - - -def nice_repr(text): - return repr(text).lstrip('u') - - -# Plot all line styles. -fig = plt.figure() -ax1 = fig.add_subplot(221) -ax2 = fig.add_subplot(222) -ax3 = fig.add_subplot(223) -ax4 = fig.add_subplot(224) - -linestyles = ['-', '--', '-.', ':'] -y1 = 1 -ax1.plot(y1 * points, linestyle='-', color=color, linewidth=3) -ax1.set_title('Line Type -') - -y2=2 -ax2.plot(y2 * points, linestyle='--', color=color, linewidth=3) -ax2.set_title('Line Type --') - -y3=3 -ax3.plot(y3* points, linestyle='-.', color=color, linewidth=3) -ax3.set_xlabel('Line Type -.') - -y4=4 -ax4.plot(y4 * points, linestyle=':', color=color, linewidth=3) -ax4.set_xlabel('Line Type :') - -plotly_fig = tls.mpl_to_plotly( fig ) -plot_url = py.plot(plotly_fig, filename='mpl-line-styles') diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-lines-and-markers_matplotlib_index.html b/_posts/matplotlib/lines-and-markers/2016-02-08-lines-and-markers_matplotlib_index.html deleted file mode 100644 index 9d69daeb0e29..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-lines-and-markers_matplotlib_index.html +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: Matplotlib Lines and markers | Examples | Plotly -name: Lines and Markers -permalink: matplotlib/lines-and-markers/ -description: Lines and markers options in matplotlib. Examples of different types of lines and markers available in matplotlib -layout: base -thumbnail: thumbnail/lines-and-markers.jpg -language: matplotlib -page_type: example_index -has_thumbnail: true -display_as: basic -order: 8 ---- -{% assign examples = site.posts | where:"language","matplotlib" | where:"suite","lines_and_markers" | sort: "order" %} -{% include auto_examples.html examples=examples %} diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-markers-color.html b/_posts/matplotlib/lines-and-markers/2016-02-08-markers-color.html deleted file mode 100644 index 5a11c4922140..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-markers-color.html +++ /dev/null @@ -1,30 +0,0 @@ ---- -name: Setting Marker Color in matplotlib -plot_url: https://plot.ly/~tarzzz/1186 -arrangement: horizontal -language: matplotlib -suite: lines_and_markers -order: 5 -sitemap: false ---- - -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -import plotly.tools as tls -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -fig = plt.figure() -ax = fig.add_subplot(111) - -x = [0,2,4,6,8,10] -y = [0]*len(x) -c = 'gbrcyk' - -ax.scatter(x,y,s=400,c=c) -ax.set_title('Plot with Different Marker Color, matplotlib and plotly') - -plotly_fig = tls.mpl_to_plotly( fig ) -plotly_url = py.plot(plotly_fig, filename='mpl-marker-color') diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-markers-edge-color.html b/_posts/matplotlib/lines-and-markers/2016-02-08-markers-edge-color.html deleted file mode 100644 index 68ce58b5d956..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-markers-edge-color.html +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: Setting Marker Edge Color in matplotlib -plot_url: https://plot.ly/~tarzzz/1198 -arrangement: horizontal -language: matplotlib -suite: lines_and_markers -order: 6 -sitemap: false ---- - -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -import plotly.tools as tls -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -fig = plt.figure() -ax = fig.add_subplot(111) - -x = [0,2,4,6,8,10] -y = [1]*len(x) -marker_edge_color = 'rgbcyk' - -for i in range(6): - ax = fig.add_subplot(2,3,i+1) - ax.plot(x,y,marker='o', markersize=20, markerfacecolor='lightgrey',markeredgecolor=marker_edge_color[i]) - ax.set_title('Edge Color: %s'%marker_edge_color[i]) - -fig.tight_layout() -plotly_fig = tls.mpl_to_plotly( fig ) -plotly_url = py.plot(plotly_fig, filename='mpl-marker-color') diff --git a/_posts/matplotlib/lines-and-markers/2016-02-08-markers-size.html b/_posts/matplotlib/lines-and-markers/2016-02-08-markers-size.html deleted file mode 100644 index 820a152a0386..000000000000 --- a/_posts/matplotlib/lines-and-markers/2016-02-08-markers-size.html +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Setting Marker Size in matplotlib -plot_url: https://plot.ly/~tarzzz/1182 -arrangement: horizontal -language: matplotlib -suite: lines_and_markers -order: 4 -sitemap: false -description: Inspired from Stack Overflow ---- - -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -import plotly.tools as tls -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -fig = plt.figure() -ax = fig.add_subplot(111) - -x = [0,2,4,6,8,10] -y = [0]*len(x) -s = [100, 400, 490, 600, 240, 160] # Specifies marker size - -ax.scatter(x,y,s=s) -ax.set_title('Plot with Different Marker size, matplotlib and plotly') - -plotly_fig = tls.mpl_to_plotly( fig ) -plotly_fig['layout']['showlegend'] = True -plotly_url = py.plot(plotly_fig, filename='mpl-marker-size') diff --git a/_posts/matplotlib/lines-and-markers/line-charts.ipynb b/_posts/matplotlib/lines-and-markers/line-charts.ipynb new file mode 100644 index 000000000000..c9a8796115c1 --- /dev/null +++ b/_posts/matplotlib/lines-and-markers/line-charts.ipynb @@ -0,0 +1,475 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### New to Plotly?\n", + "Plotly's Python library is free and open source! [Get started](https://plot.ly/python/getting-started/) by downloading the client and [reading the primer](https://plot.ly/python/getting-started/).\n", + "
You can set up Plotly to work in [online](https://plot.ly/python/getting-started/#initialization-for-online-plotting) or [offline](https://plot.ly/python/getting-started/#initialization-for-offline-plotting) mode, or in [jupyter notebooks](https://plot.ly/python/getting-started/#start-plotting-online).\n", + "
We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Version Check\n", + "Plotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'3.1.1'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly\n", + "plotly.__version__" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Passing Line Styles As List" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "color = 'cornflowerblue'\n", + "points = np.ones(5) # Draw 5 points for each line\n", + "text_style = dict(horizontalalignment='right', verticalalignment='center',\n", + " fontsize=12, fontdict={'family': 'monospace'})\n", + "\n", + "\n", + "def format_axes(ax):\n", + " ax.margins(0.2)\n", + " ax.set_axis_off()\n", + "\n", + "\n", + "def nice_repr(text):\n", + " return repr(text).lstrip('u')\n", + "\n", + "\n", + "# Plot all line styles.\n", + "fig = plt.figure()\n", + "ax1 = fig.add_subplot(221)\n", + "ax2 = fig.add_subplot(222)\n", + "ax3 = fig.add_subplot(223)\n", + "ax4 = fig.add_subplot(224)\n", + "\n", + "linestyles = ['-', '--', '-.']\n", + "y1 = 1\n", + "ax1.plot(y1 * points, linestyle='-', color=color, linewidth=3)\n", + "ax1.set_title('Line Type -')\n", + "\n", + "y2=2\n", + "ax2.plot(y2 * points, linestyle='--', color=color, linewidth=3)\n", + "ax2.set_title('Line Type --')\n", + "\n", + "y3=3\n", + "ax3.plot(y3* points, linestyle='-.', color=color, linewidth=3)\n", + "ax3.set_xlabel('Line Type -.')\n", + "\n", + "plotly_fig = tls.mpl_to_plotly( fig )\n", + "py.iplot(plotly_fig, filename='mpl-linestyles')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setting Linestyles Per Column In Pandas\n", + "Inspired From [Pandas Docs](http://pandas.pydata.org/pandas-docs/version/0.17.1/generated/pandas.Series.plot.html)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "\n", + "x = np.linspace(-5,5,1000)\n", + "sinx = np.sin(x)\n", + "cosx = np.cos(x)\n", + "logx = np.log(x)\n", + "\n", + "df = pd.DataFrame({'x':x, 'sinx':sinx, 'cosx':cosx, 'logx':logx})\n", + "\n", + "ax = df.plot(kind='line', style=['-', '--', '-.'], legend=False)\n", + "ax.set_title('Setting Line Styles Per column in Matplotlib and pandas')\n", + "fig = ax.get_figure()\n", + "\n", + "plotly_fig = tls.mpl_to_plotly( fig )\n", + "plotly_fig['layout']['showlegend'] = True\n", + "py.iplot(plotly_fig, filename='mpl-linestyles-column')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Cycling Through Various Line Styles\n", + "Inspired From [Stack Overflow](http://stackoverflow.com/questions/7799156/can-i-cycle-through-line-styles-in-matplotlib)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "from itertools import cycle\n", + "\n", + "lines = [\"-\",\"--\",\"-.\"]\n", + "linecycler = cycle(lines)\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(111)\n", + "for i in range(10):\n", + " x = range(i,i+10)\n", + " ax.plot(range(10),x,next(linecycler))\n", + "\n", + "ax.set_title('Cycling through line styles in matplotlib')\n", + "\n", + "plotly_fig = tls.mpl_to_plotly( fig )\n", + "py.iplot(plotly_fig, filename='mpl-cycle-linestyles')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setting Marker Size In Matplotlib\n", + "Inspired From [Stack Overflow](http://stackoverflow.com/questions/14827650/pyplot-scatter-plot-marker-size)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(111)\n", + "\n", + "x = [0,2,4,6,8,10]\n", + "y = [0]*len(x)\n", + "s = [100, 400, 490, 600, 240, 160] # Specifies marker size\n", + "\n", + "ax.scatter(x,y,s=s)\n", + "ax.set_title('Plot with Different Marker size, matplotlib and plotly')\n", + "\n", + "plotly_fig = tls.mpl_to_plotly( fig )\n", + "plotly_fig['layout']['showlegend'] = True\n", + "py.iplot(plotly_fig, filename='mpl-marker-size')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setting Marker Color In Matplotlib" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(111)\n", + "\n", + "x = [0,2,4,6,8,10]\n", + "y = [0]*len(x)\n", + "c = 'gbrcyk'\n", + "\n", + "ax.scatter(x,y,s=400,c=c)\n", + "ax.set_title('Plot with Different Marker Color, matplotlib and plotly')\n", + "\n", + "plotly_fig = tls.mpl_to_plotly( fig )\n", + "py.iplot(plotly_fig, filename='mpl-marker-color')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Setting Marker Edge Color in matplotlib\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import plotly.plotly as py\n", + "import plotly.tools as tls\n", + "\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "fig = plt.figure()\n", + "ax = fig.add_subplot(111)\n", + "\n", + "x = [0,2,4,6,8,10]\n", + "y = [1]*len(x)\n", + "marker_edge_color = 'rgbcyk'\n", + "\n", + "for i in range(6):\n", + " ax = fig.add_subplot(2,3,i+1)\n", + " ax.plot(x,y,marker='o', markersize=20, markerfacecolor='lightgrey',markeredgecolor=marker_edge_color[i])\n", + " ax.set_title('Edge Color: %s'%marker_edge_color[i])\n", + "\n", + "fig.tight_layout()\n", + "plotly_fig = tls.mpl_to_plotly( fig )\n", + "py.iplot(plotly_fig, filename='mpl-marker-edge')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Reference\n", + "See https://plot.ly/python/reference/ for more information and chart attribute options!" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "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 c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-agoeda\n", + "Building wheels for collected packages: publisher\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-_miraw\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + "Successfully built publisher\n", + "Installing collected packages: publisher\n", + " Found existing installation: publisher 0.11\n", + " Uninstalling publisher-0.11:\n", + " Successfully uninstalled publisher-0.11\n", + "Successfully installed publisher-0.11\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Anaconda\\Anaconda2\\lib\\site-packages\\IPython\\nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", + " \"You should import from nbconvert instead.\", ShimWarning)\n", + "C:\\Anaconda\\Anaconda2\\lib\\site-packages\\publisher\\publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", + " warnings.warn('Did you \"Save\" this notebook before running this command? '\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", + " 'line-charts.ipynb', 'matplotlib/line-charts/', 'Lines and Markers',\n", + " 'Lines and markers options in matplotlib. Examples of different types of lines and markers available in matplotlib.',\n", + " title = 'Lines and markers | Plotly',\n", + " has_thumbnail='true', thumbnail='thumbnail/lines-and-markers.jpg',\n", + " language='matplotlib',\n", + " page_type='example_index',\n", + " display_as='basic', ipynb='~notebook_demo/234',\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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.14" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/_posts/matplotlib/redirects/2018-08-23-lines-and-markers.html b/_posts/matplotlib/redirects/2018-08-23-lines-and-markers.html new file mode 100644 index 000000000000..a2124e2c8850 --- /dev/null +++ b/_posts/matplotlib/redirects/2018-08-23-lines-and-markers.html @@ -0,0 +1,5 @@ +--- +permalink: matplotlib/lines-and-markers/ +redirect_to: https://plot.ly/matplotlib/line-charts/ +sitemap: false +--- diff --git a/_posts/matplotlib/redirects/2018-08-23-scatter_exclusive.html b/_posts/matplotlib/redirects/2018-08-23-scatter_exclusive.html new file mode 100644 index 000000000000..84d9337e3ba4 --- /dev/null +++ b/_posts/matplotlib/redirects/2018-08-23-scatter_exclusive.html @@ -0,0 +1,5 @@ +--- +permalink: matplotlib/scatter/ +redirect_to: https://plot.ly/matplotlib/line-and-scatter/ +sitemap: false +--- diff --git a/_posts/matplotlib/scatter_exclusive/2015-04-09-mpl-complex-scatter.html b/_posts/matplotlib/scatter_exclusive/2015-04-09-mpl-complex-scatter.html deleted file mode 100755 index bbda8981fc98..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2015-04-09-mpl-complex-scatter.html +++ /dev/null @@ -1,30 +0,0 @@ ---- -name: Matplotlib Scatter Colors and Symbols -plot_url: https://plot.ly/~PlotBot/133 -arrangement: horizontal -language: matplotlib -suite: scatter_exclusive -order: 3 -sitemap: false ---- -import matplotlib.pyplot as plt -import plotly.plotly as py -import numpy as np - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -fig, ax = plt.subplots() -num = 1000 -s = 121 -x1 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num)) -y1 = np.linspace(-5,5,num) + (0.5 - np.random.rand(num)) -x2 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num)) -y2 = np.linspace(5,-5,num) + (0.5 - np.random.rand(num)) -x3 = np.linspace(-0.5,1,num) + (0.5 - np.random.rand(num)) -y3 = (0.5 - np.random.rand(num)) -ax.scatter(x1, y1, color='r', s=2*s, marker='^', alpha=.4) -ax.scatter(x2, y2, color='b', s=s/2, alpha=.4) -ax.scatter(x3, y3, color='g', s=s/3, marker='s', alpha=.4) - -plot_url = py.plot_mpl(fig, filename="mpl-complex-scatter") diff --git a/_posts/matplotlib/scatter_exclusive/2015-04-09-mpl-scatter.html b/_posts/matplotlib/scatter_exclusive/2015-04-09-mpl-scatter.html deleted file mode 100755 index 41a4409cf434..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2015-04-09-mpl-scatter.html +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Basic Matplotlib Scatter Plot -plot_url: https://plot.ly/~PlotBot/134 -arrangement: horizontal -language: matplotlib -suite: scatter_exclusive -order: 2 -sitemap: false ---- -import matplotlib.pyplot as plt -import plotly.plotly as py -import numpy as np - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -fig, ax = plt.subplots() -ax.scatter(np.linspace(-1, 1, 50), np.random.randn(50)) - -plot_url = py.plot_mpl(fig, filename="mpl-scatter") diff --git a/_posts/matplotlib/scatter_exclusive/2015-04-09-scatter_exclusive_matplotlib_index.html b/_posts/matplotlib/scatter_exclusive/2015-04-09-scatter_exclusive_matplotlib_index.html deleted file mode 100755 index 165a728f4b87..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2015-04-09-scatter_exclusive_matplotlib_index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: matplotlib Scatter | Examples | Plotly -name: Scatter -permalink: matplotlib/scatter/ -description: How to make a scatter plot in matplotlib. Seven examples of the scatter function. -layout: base -thumbnail: thumbnail/scatter_exclusive.jpg -language: matplotlib -page_type: example_index -has_thumbnail: true -display_as: chart_type ---- -{% assign examples = site.posts | where:"language","matplotlib" | where:"suite","scatter_exclusive" | sort: "order" %} -{% include auto_examples.html examples=examples %} diff --git a/_posts/matplotlib/scatter_exclusive/2015-08-20-adding-line.html b/_posts/matplotlib/scatter_exclusive/2015-08-20-adding-line.html deleted file mode 100644 index 51042ff251f6..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2015-08-20-adding-line.html +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: adding a line to a plot -plot_url: https://plot.ly/~MattSundquist/19623/-line0-line1-line2/ -arrangement: horizontal -language: matplotlib -suite: scatter_exclusive -description: Inspired by Stack Overflow. -order: 1 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import numpy as np -import matplotlib.pyplot as plt -import plotly.plotly as py - -line = plt.figure() - -np.random.seed(5) -x = np.arange(1, 101) -y = 20 + 3 * x + np.random.normal(0, 60, 100) -plt.plot(x, y, "o") - - -# draw vertical line from (70,100) to (70, 250) -plt.plot([70, 70], [100, 250], 'k-', lw=2) - -# draw diagonal line from (70, 90) to (90, 200) -plt.plot([70, 90], [90, 200], 'k-') - -plot_url = py.plot_mpl(line, filename='mpl-docs/add-line') diff --git a/_posts/matplotlib/scatter_exclusive/2015-08-20-color-options.html b/_posts/matplotlib/scatter_exclusive/2015-08-20-color-options.html deleted file mode 100644 index a60f75f92d9d..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2015-08-20-color-options.html +++ /dev/null @@ -1,31 +0,0 @@ ---- -name: color and marker options -plot_url: https://plot.ly/~MattSundquist/19635 -arrangement: horizontal -language: matplotlib -suite: scatter_exclusive -description: Inspired by Stack Overflow. -order: 5 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -from pylab import * -import plotly.plotly as py # tools to communicate with Plotly's server - -scatter = plt.figure() - -colors = (i + j for j in 'o<.' for i in 'bgrcmyk') -labels = 'one two three four five six seven eight nine ten'.split() -x = linspace(0, 2*pi, 3000) -d = (2+random((2,3000))) * c_[sin(x), cos(x)].T -lg = [] -for i, l, c in zip(range(10), labels, colors): - start, stop = i * 300, (i + 1) * 300 - handle = plot(d[0, start:stop], d[1, start:stop], c, label=l) - lg.append(handle) -show() - -plot_url = py.plot_mpl(scatter, filename='mpl-docs/scatter') diff --git a/_posts/matplotlib/scatter_exclusive/2015-08-20-duplicate-points.html b/_posts/matplotlib/scatter_exclusive/2015-08-20-duplicate-points.html deleted file mode 100644 index f423ee4f29f8..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2015-08-20-duplicate-points.html +++ /dev/null @@ -1,26 +0,0 @@ ---- -name: scatter plot with duplicate points -plot_url: https://plot.ly/~MattSundquist/19629 -arrangement: horizontal -language: matplotlib -suite: scatter_exclusive -description: Inspired by Stack Overflow. -order: 4 -sitemap: false ---- - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - -import numpy as np -import matplotlib.pyplot as plt -import plotly.plotly as py # tools to communicate with Plotly's server - -alpha = plt.figure() - -data = [i for i in range(8) for j in range(np.random.randint(10))] -x, y = np.array(data), np.array(data) -plt.scatter(x, y, alpha=.1, s=400) -plt.show() - -plot_url = py.plot_mpl(alpha, filename='mpl-docs/alpha') diff --git a/_posts/matplotlib/scatter_exclusive/2016-02-12-mpl-scatter-legend.html b/_posts/matplotlib/scatter_exclusive/2016-02-12-mpl-scatter-legend.html deleted file mode 100644 index e8e1ae4f4766..000000000000 --- a/_posts/matplotlib/scatter_exclusive/2016-02-12-mpl-scatter-legend.html +++ /dev/null @@ -1,44 +0,0 @@ ---- -name: Scatter Plot with Legend and Label -plot_url: https://plot.ly/~tarzzz/1285 -arrangement: horizontal -language: matplotlib -suite: scatter_exclusive -order: 6 -sitemap: false -description: Inspired from Stack Overflow ---- - - -import matplotlib.pyplot as plt -import numpy as np - -import plotly.plotly as py -import plotly.tools as tls - -# Learn about API authentication here: https://plot.ly/python/getting-started -# Find your api_key here: https://plot.ly/settings/api - - -colors = ['b', 'c', 'y', 'm', 'r'] - -lo = plt.scatter(random(10), random(10), marker='x', color=colors[0]) -ll = plt.scatter(random(10), random(10), marker='o', color=colors[0]) -l = plt.scatter(random(10), random(10), marker='o', color=colors[1]) -a = plt.scatter(random(10), random(10), marker='o', color=colors[2]) -h = plt.scatter(random(10), random(10), marker='o', color=colors[3]) -hh = plt.scatter(random(10), random(10), marker='o', color=colors[4]) -ho = plt.scatter(random(10), random(10), marker='x', color=colors[4]) - -text = iter(['Low Outlier', 'LoLo', 'Lo', 'Average', 'Hi', 'HiHi', 'High Outlier']) - - -mpl_fig = plt.gcf() -plotly_fig = tls.mpl_to_plotly( mpl_fig ) - -for dat in plotly_fig['data']: - t = text.next() - dat.update({'name': t, 'text':t}) - -plotly_fig['layout']['showlegend'] = True -py.plot(plotly_fig)