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 %} +
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!
Plotly's python package is updated frequently. Run pip install plotly --upgrade
to use the latest version.
import plotly
+plotly.__version__
+
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')
+
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')
+
Inspired From Stack Overflow
+ +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')
+
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')
+
Inspired From Stack Overflow
+ +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')
+
Inspired From Stack Overflow
+ +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')
+
Inspired From Stack Overflow
+ +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')
+
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')
+
See https://plot.ly/python/reference/ for more information and chart attribute options!
+ +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
+ +Plotly's python package is updated frequently. Run pip install plotly --upgrade
to use the latest version.
import plotly
+plotly.__version__
+
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)
+
Inspired by Stack Overflow
+ +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)
+
Inspired by Stack Overflow
+ +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)
+
Inspired by Stack Overflow
+ +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)
+
Inspired by Stack Overflow
+ +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)
+
Inspired by Stack Overflow
+ +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)
+
See https://plot.ly/python/reference/ for more information and chart attribute options!
+ +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!
Plotly's python package is updated frequently. Run pip install plotly --upgrade
to use the latest version.
import plotly
+plotly.__version__
+
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')
+
Inspired From Pandas Docs
+ +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')
+
Inspired From Stack Overflow
+ +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')
+
Inspired From Stack Overflow
+ +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')
+
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')
+
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')
+
See https://plot.ly/python/reference/ for more information and chart attribute options!
+ +