Enriching axes with ticks, labels, and legends
The charts can be further improved by customizing the axes via ticks, limits, and labels.
The matplotlib.pyplot.xlim(...)
method sets the range of values on the x axis.
The matplotlib.pyplot.xticks(...)
method specifies where the ticks show up on the x axis:
plt.xlim([8, 10.5]) plt.xticks([8, 8.42, 8.94, 9.47, 10, 10.5]) plt.plot(x, y1, color='black', linestyle='--', marker='o')
This modifies the x axis to be within the specified limits and the ticks at the explicitly specified values:
We can also change the scale of one of the axes to non-linear using the matplotlib.Axes.set_yscale(...)
method.
The matplotlib.Axes.set_xticklabels(...)
method changes the labels on the x axis:
fig, ax = plt.subplots(1, figsize=(12, 6)) ax.set_yscale('log') ax.set_xticks(x) ax.set_xticklabels(list(...