... compare these numbers with our sorting function example, eh?
from matplotlib import pyplot as plt
import numpy as np
# configuring the plot
plt.figure(dpi=220, figsize=(5,3)) # dot-per-inch ; plot size in inches
plt.xlabel('x')
plt.ylabel('y')
plt.title('a plot')
# some numbers that we want to plot
x = [100, 300, 1000, 3000]
y = [2.4, 19.0, 180.0, 2100.0]
plt.scatter(x, y, color="red", label="some numbers")
# and let's also plot a curve on the same plot
# ... with some trial-and-error for the constants in the `ys = ...` equation.
xs = np.linspace(100, 3000) # "linear spaced points" ... an array
ys = xs * xs * 2.0 / 10000 # numpy (numerical python) does an implied loop over the array
plt.plot(xs, ys, color="blue", label="curve fit")
# add the labels so we can see what's what
plt.legend()
None
plt.figure(dpi=220, figsize=(5,3)) # dot-per-inch ; plot size in inches
plt.xlabel('x')
plt.ylabel('y')
plt.title('a plot')
x = [100, 300, 1000, 3000]
y = [2.4, 19.0, 180.0, 2100.0]
plt.scatter(x, y, color="red", label="some numbers")
xs = np.linspace(100, 3000)
ys = xs * xs * 2.0 / 10000
plt.plot(xs, ys, color="blue", label="curve fit")
plt.legend()
# Same with a log-log scale
plt.xscale('log')
plt.yscale('log')