%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0,10)
y = np.arange(0,10)
plt.plot(x,y)
There are some great defaults to make these plots pretty!
print plt.style.available
plt.style.use('fivethirtyeight')
plt.plot(x,y)
plt.style.use('ggplot')
plt.plot(x,y)
x = np.arange(-10,10)
a = np.arange(0,20)
b = [b**2 for b in range(0,20)]
c = [100 for c in range(0,20)]
plt.title("Some Squiggles")
plt.plot(x,a, label='linear')
plt.plot(x,b, label='exponential')
plt.plot(x,c, label='flat')
plt.legend(loc='upper left', frameon=True)
plt.ylabel('The Y Label')
plt.xlabel('The X Label')
n = 1000
ax = np.random.randn(n)
ay = np.random.randn(n)
plt.scatter(ax, ay)
I like using Tableau's color set because of the visual balance. Here's how you load that into matplotlib!
# These are the "Tableau 20" colors as RGB.
tableau20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),
(44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),
(148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),
(227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),
(188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]
# Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts.
for i in range(len(tableau20)):
r, g, b = tableau20[i]
tableau20[i] = (r / 255., g / 255., b / 255.)
# c for color, alpha for transparency
plt.scatter(ax, ay, c=tableau20[4], alpha=0.75)