【3.7.5】matplotlib-循环用色
代码:
"""
====================================
Colors in the default property cycle
====================================
Display the colors from the default prop_cycle.
"""
import numpy as np
import matplotlib.pyplot as plt
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
lwbase = plt.rcParams['lines.linewidth'] #基本线条尺寸
thin = float('%.1f' % (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('line widths (pts): %.1f, %.1f' % (lwx, lwy),
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()
这里是一个广告位,,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn