注意
转到结尾 下载完整示例代码。
默认属性循环中的颜色#
显示来自默认 prop_cycle 的颜色,该颜色是从 rc 参数 获得的。
import matplotlib.pyplot as plt
import numpy as np
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
lwbase = plt.rcParams['lines.linewidth']
thin = lwbase / 2
thick = lwbase * 3
fig, axs = plt.subplots(nrows=2, ncols=2, sharex=True, sharey=True)
for icol in range(2):
if icol == 0:
lwx, lwy = thin, lwbase
else:
lwx, lwy = lwbase, thick
for irow in range(2):
for i, color in enumerate(colors):
axs[irow, icol].axhline(i, color=color, lw=lwx)
axs[irow, icol].axvline(i, color=color, lw=lwy)
axs[1, icol].set_facecolor('k')
axs[1, icol].xaxis.set_ticks(np.arange(0, 10, 2))
axs[0, icol].set_title(f'line widths (pts): {lwx:g}, {lwy:g}',
fontsize='medium')
for irow in range(2):
axs[irow, 0].yaxis.set_ticks(np.arange(0, 10, 2))
fig.suptitle('Colors in the default prop_cycle', fontsize='large')
plt.show()
参考资料
本示例展示了以下函数、方法、类和模块的使用