这是一些创建类似颜色条的代码:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import LinearSegmentedColormap
def burr_pdf(x, c, k):
return c * k * (x ** (c - 1)) / (1 + x ** c) ** (k + 1)
xs = np.linspace(0.0001, 3, 300)
c_k_params = [(1, 1), (1, 2), (1, 3), (2, 1), (3, 1), (0.5, 2)]
curve_labels = [f'c={c}; k={k}' for c, k in c_k_params]
curve_colors = np.linspace(0.98, 0.02, len(c_k_params))
cmap = cm.get_cmap('jet')
special_map_list = [tuple((c+2)/3 for c in cmap(i/256)) for i in range(256)] # "whiten" the colors
for c in curve_colors:
special_map_list[int(c*256)] = cmap(c)
special_map_list[int(c*256)-1] = cmap(c)
special_map = LinearSegmentedColormap.from_list('', special_map_list)
fig, ax = plt.subplots(figsize=(7, 7))
for (c, k), col in zip(c_k_params, curve_colors):
ax.plot(xs, burr_pdf(xs, c, k), color=cmap(col))
ax.set_title('Burr – probability density function')
ax.set_ylim((0, 2))
ax.set_xlim((0, 3))
cbar = plt.colorbar(cm.ScalarMappable(norm=None, cmap=special_map), ax=ax, ticks=curve_colors)
cbar.ax.set_yticklabels(curve_labels)
plt.show()
曲线来自维基百科的Burr分布。剧情:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句