<jupyter_start><jupyter_text>New to Plotly?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/).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).We also have a quick-reference [cheatsheet](https://images.plot.ly/plotly-documentation/images/python_cheat_sheet.pdf) (new!) to help you get started!  Version CheckPlotly's python package is updated frequently. Run `pip install plotly --upgrade` to use the latest version.<jupyter_code>import plotly
plotly.__version__<jupyter_output><empty_output><jupyter_text>Basic Scatter Plot<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Line and Scatter Plot<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Adding Line To Matplotlib Scatter PlotInspired From [Stack Overflow](https://stackoverflow.com/questions/12864294/adding-an-arbitrary-line-to-a-matplotlib-plot-in-ipython-notebook)<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Matplotlib Scatter Colors And Symbols<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Scatter Plot With Duplicate PointsInspired From [Stack Overflow](https://stackoverflow.com/questions/21081453/drawing-scatter-graph-using-matlibplot-pyplot-when-points-are-duplicate)<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Color And Marker OptionsInspired From [Stack Overflow](https://stackoverflow.com/questions/872397/matplotlib-legend-not-displayed-properly)<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Scatter Plot With Legend And LabelInspired From [Stack Overflow](https://stackoverflow.com/questions/17411940/matplotlib-scatter-plot-legend)<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>Colored Matplotlib Line Chart<jupyter_code>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')<jupyter_output><empty_output><jupyter_text>ReferenceSee https://plot.ly/python/reference/ for more information and chart attribute options!<jupyter_code>from IPython.display import display, HTML

display(HTML('<link href="//fonts.googleapis.com/css?family=Open+Sans:600,400,300,200|Inconsolata|Ubuntu+Mono:400,700" rel="stylesheet" type="text/css" />'))
display(HTML('<link rel="stylesheet" type="text/css" href="http://help.plot.ly/documentation/all_static/css/ipython-notebook-custom.css">'))

! pip install git+https://github.com/plotly/publisher.git --upgrade
import publisher
publisher.publish(
    'line_and_scatter.ipynb', 'matplotlib/line-and-scatter/', 'Line and Scatter Plots',
    'How to make line and scatter plots in matplotlib.',
    title = 'Line and Scatter Plots | Plotly',
    has_thumbnail='true', thumbnail='thumbnail/line-and-scatter.jpg',
    language='matplotlib',
    page_type='example_index',
    display_as='basic', ipynb='~notebook_demo/243')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15963813500347948, 'fraction_numerical': 0.0336812804453723, 'mean_word_length': 5.616942909760589, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 43, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '452578', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 2931, 'n_tokens_neox': 2755, 'n_words': 595, 'path': '_posts/matplotlib/line_and_scatter/line_and_scatter.ipynb', 'repo_name': 'bmb804/documentation', 'size': '7185'}