更改绘图大小:
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = (20,3)
更改坐标轴显示形式(科学记数法等):
import matplotlib.ticker as mticker
ax.xaxis.set_major_formatter(mticker.ScalarFormatter())
两个 y 轴,分别显示图例:
fig = plt.figure()
ax = fig.add_subplot(111)
bw_t, bw = get_bw(f'{bwInBps}.csv')
ax.plot(bw_t, bw, label="bw")
trace_t, trace = get_nw(tracefile)
ax.step(trace_t, trace, label="trace")
ax2 = ax.twinx()
delay_t, delay = get_delay(f'{bwInBps}.csv')
ax2.plot(delay_t, delay, color='g', label='delay')
# ask matplotlib for the plotted objects and their labels
lines, labels = ax.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax2.legend(lines + lines2, labels + labels2, loc=0)
带有比例的 subplots
f, (a0, a1) = plt.subplots(2, 1, figsize=(13, 9), gridspec_kw={'height_ratios': [3, 1]})
3D axes:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')