Scatter Plots

Perhaps the 2nd most well-known type of plot, also so generic that it is called with the same plot function as with line plots.


In [1]:
import numpy
from matplotlib import pyplot
%matplotlib inline

###  generate some random data
xdata = numpy.arange(15)
ydata = numpy.random.randn(15) + xdata

###  initialize the "figure" and "axes" objects
fig, ax = pyplot.subplots()

points_plot = ax.plot(xdata, ydata, marker='o')


Ok you got me, the plot function still generates a line by default... but we can turn it off


In [2]:
###  initialize the figure
fig, ax = pyplot.subplots()

points_plot = ax.plot(xdata, ydata, ls='', marker='o')



Markersize


In [3]:
###  initialize the figure
fig, ax = pyplot.subplots()

points_plot = ax.plot(xdata, ydata, ls='', marker='o', ms=15)



Symbol


In [4]:
###  initialize the figure
fig, ax = pyplot.subplots()

points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='o')
#points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='s')
#points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='D')

#points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='^')
#points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='>')
#points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='<')
#points_plot = ax.plot(xdata, ydata, ls='', ms=8, marker='v')



Errorbars


In [5]:
###  generate some random data
xdata2 = numpy.arange(15)
ydata2 = numpy.random.randn(15)
yerrors = numpy.random.randn(15)

###  initialize the figure
fig, ax = pyplot.subplots()

ax.errorbar(xdata2, ydata2, yerr=yerrors)


Out[5]:
<Container object of 3 artists>

In [6]:
###  initialize the figure
fig, ax = pyplot.subplots()


eb = ax.errorbar(xdata2, ydata2, yerr=yerrors, ls='',         # no lines connecting points
                                               marker='*',    # circular plot symbols
                                               ms=20,         # marker size
                                               mfc='r',       # marker face color
                                               mew=2,         # marker edge width
                                               mec='k',       # marker edge color
                                               elinewidth=2,  # error line width
                                               ecolor='gray', # error color
                                               capsize=6)     # error hat size

###  also try mfc="none"



In [ ]:
pyplot.errorbar?

In [ ]: