import matplotlib.pyplot as plt import numpy as np if __name__ == "__main__": # wikipedia: # Generally, males vary in total length from 250 to 390 cm and # weigh between 90 and 306 kg c = 6 x = np.arange(2.2, 3.9, 0.05) y = c * x**3.0 rng = np.random.RandomState(32281) noise = rng.randn(len(x))*50 y += noise plt.xkcd() fig, ax = plt.subplots(figsize=(7., 3.6)) ax.scatter(x, y, marker='o', color='b', s=40, zorder=10) xx = np.linspace(2.1, 3.9, 100) ax.plot(xx, c*xx**3.0, color='#CC0000', lw=3, zorder=5) for cc in [0.25*c, 0.5*c, 2.0*c, 4.0*c]: ax.plot(xx, cc*xx**3.0, color='#FF9900', lw=2, zorder=5) ax.spines["right"].set_visible(False) ax.spines["top"].set_visible(False) ax.yaxis.set_ticks_position('left') ax.xaxis.set_ticks_position('bottom') ax.tick_params(direction="out", width=1.25) ax.tick_params(direction="out", width=1.25) ax.set_xlabel('Size x / m') ax.set_ylabel('Weight y / kg') ax.set_xlim(2, 4) ax.set_ylim(0, 400) ax.set_xticks(np.arange(2.0, 4.1, 0.5)) ax.set_yticks(np.arange(0, 401, 100)) fig.set_facecolor("white") fig.subplots_adjust(0.11, 0.16, 0.98, 0.97) fig.savefig("cubicfunc.pdf") plt.close()