35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
from plotstyle import *
|
|
|
|
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
|
|
|
|
fig, ax = plt.subplots(figsize=cm_size(figure_width, 1.4*figure_height))
|
|
fig.subplots_adjust(**adjust_fs(left=6.0, right=1.2))
|
|
|
|
ax.scatter(x, y, marker='o', color=colors['blue'], s=40, zorder=10)
|
|
xx = np.linspace(2.1, 3.9, 100)
|
|
ax.plot(xx, c*xx**3.0, color=colors['red'], 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=colors['orange'], lw=2, zorder=5)
|
|
|
|
show_spines(ax, 'lb')
|
|
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.savefig("cubicfunc.pdf")
|
|
plt.close()
|