利用 matplotlib 中的 xkcd 功能将绘图转换为手写风格
plt.xkcd() # 开启 xkcd 模式
In [1]:
import numpy as np
from matplotlib import pyplot as plt
# from IPython.core.interactiveshell import InteractiveShell
# InteractiveShell.ast_node_interactivity = "all"
%matplotlib inline
%pylab inline
In [2]:
plt.xkcd() # 开启手写风格模式
plt.plot(sin(linspace(0, 10)))
plt.title('Whoo Hoo!!!')
Out[2]:
In [3]:
x = np.linspace(0, 10)
y1 = x * np.sin(x)
y2 = x * np.cos(x)
plt.fill(x, y1, 'red', alpha=0.4)
plt.fill(x, y2, 'blue', alpha=0.4)
plt.xlabel('x axis yo!')
plt.ylabel("I don't even know")
Out[3]:
In [4]:
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(0, 10, 30)
colors = ['r', 'g', 'b', 'y']
y = np.random.random((len(colors), len(x)))
y[:, 0] = y[:, -1] = 0
edges = [list(zip(x, yi)) for yi in y]
poly = PolyCollection(edges, facecolors=colors, alpha=0.6)
ax.add_collection3d(poly, zs=range(4), zdir='y')
ax.set_xlabel('X')
ax.set_xlim3d(0, 10)
ax.set_ylabel('Y')
ax.set_ylim3d(-1, 4)
ax.set_zlabel('Z')
ax.set_zlim3d(0, 1)
Out[4]:
In [5]:
fig = plt.figure(figsize=(8, 6))
ax = fig.add_subplot(211)
years = np.linspace(1975, 2013)
pct = 2 + 98. / (1 + np.exp(0.6 * (2008 - years)))
ax.plot(years, pct)
ax.set_xlim(1976, 2013)
ax.set_ylim(0, 100)
ax.yaxis.set_major_formatter(plt.FormatStrFormatter('%i%%'))
ax.text(1977, 67,
("Percentage of the US Population\n"
"carrying cameras everywhere they go,\n"
"every waking moment of their lives:"),
size=16)
ax.set_xlabel(("In the last few years, with very little fanfare,\n"
"We've conclusively settled the questions of\n"
"flying saucers, lake monsters, ghosts, and bigfoot."),
size=16)
Out[5]: