fig, ax = plt.subplots()
# plot() is used for scatter charts and line charts only
# similar to ax.scatter()
ax.plot(*args, data=None, scalex=True, scaley=True, **kwargs)
#-------------------------------------------------------------#
# Primary call signature
plot([x], y, [fmt], data=None, **kwargs)
#-------------------------------------------------------------#
# Can omit x
plot(y) # plot y using x as index array 0..N-1
#-------------------------------------------------------------#
# [fmt] : convenience shortcut string notation for kwargs
# fmt = '[color][marker][linestyle]'
# Equivalent:
plot(x, y,
'go--',
linewidth=2, markersize=12)
plot(x, y,
color='green', marker='o', linestyle='dashed',
linewidth=2, markersize=12)
# More examples:
plot(x, y, 'bo') # blue circles
plot(y, 'r+') # red pluses
#-------------------------------------------------------------#
# To plot multiple sets of data on same ax
# A) call it twice:
plot(x1, y1, 'bo')
plot(x2, y2, 'go')
# B) Use Secondary (grouped) call signature
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
plot(x1, y1, 'g^', x2, y2, 'g-')
# C) df where df[0] is x and df[1:] are y's
plot(a[0], a[1:])
#-------------------------------------------------------------#
# Using data param:
# where data is indexed obj like dict or df
plot('xlabel', 'ylabel', data=obj)
#-------------------------------------------------------------#
# Common **kwargs:
plot(x, y, label='line 2') # label is for y
plot(x, y,
color='green', marker='o', linestyle='dashed',
linewidth=2, markersize=12)
# Note - the below is a python feature (**kwargs), not MPL:
ax.plot(data1, data2, **{'color':'green',
'marker':'x',
'linestyle':'dashed'})
Comments