当前位置:   article > 正文

Python使用matplotlib可视化绘图时你可用的颜色有哪些?把色彩可视化出来自己选好了_python matplotlib 一般选什么颜色

python matplotlib 一般选什么颜色

Python使用matplotlib可视化绘图时你可用的颜色有哪些?把色彩可视化出来自己选好了

目录

Python使用matplotlib可视化绘图时你可用的颜色有哪些?把色彩可视化出来自己选好了

#基础色彩

#画面调色板色彩

​ #CSS色彩

#代码查看可用色谱

List of named colors


#基础色彩

#画面调色板色彩

 #CSS色彩

#代码查看可用色谱

  1. from matplotlib.patches import Rectangle
  2. import matplotlib.pyplot as plt
  3. import matplotlib.colors as mcolors
  4. def plot_colortable(colors, title, sort_colors=True, emptycols=0):
  5. cell_width = 212
  6. cell_height = 22
  7. swatch_width = 48
  8. margin = 12
  9. topmargin = 40
  10. # Sort colors by hue, saturation, value and name.
  11. if sort_colors is True:
  12. by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(color))),
  13. name)
  14. for name, color in colors.items())
  15. names = [name for hsv, name in by_hsv]
  16. else:
  17. names = list(colors)
  18. n = len(names)
  19. ncols = 4 - emptycols
  20. nrows = n // ncols + int(n % ncols > 0)
  21. width = cell_width * 4 + 2 * margin
  22. height = cell_height * nrows + margin + topmargin
  23. dpi = 72
  24. fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), dpi=dpi)
  25. fig.subplots_adjust(margin/width, margin/height,
  26. (width-margin)/width, (height-topmargin)/height)
  27. ax.set_xlim(0, cell_width * 4)
  28. ax.set_ylim(cell_height * (nrows-0.5), -cell_height/2.)
  29. ax.yaxis.set_visible(False)
  30. ax.xaxis.set_visible(False)
  31. ax.set_axis_off()
  32. ax.set_title(title, fontsize=24, loc="left", pad=10)
  33. for i, name in enumerate(names):
  34. row = i % nrows
  35. col = i // nrows
  36. y = row * cell_height
  37. swatch_start_x = cell_width * col
  38. text_pos_x = cell_width * col + swatch_width + 7
  39. ax.text(text_pos_x, y, name, fontsize=14,
  40. horizontalalignment='left',
  41. verticalalignment='center')
  42. ax.add_patch(
  43. Rectangle(xy=(swatch_start_x, y-9), width=swatch_width,
  44. height=18, facecolor=colors[name], edgecolor='0.7')
  45. )
  46. return fig
  47. plot_colortable(mcolors.BASE_COLORS, "Base Colors",
  48. sort_colors=False, emptycols=1)
  49. plot_colortable(mcolors.TABLEAU_COLORS, "Tableau Palette",
  50. sort_colors=False, emptycols=2)
  51. plot_colortable(mcolors.CSS4_COLORS, "CSS Colors")
  52. # Optionally plot the XKCD colors (Caution: will produce large figure)
  53. #xkcd_fig = plot_colortable(mcolors.XKCD_COLORS, "XKCD Colors")
  54. #xkcd_fig.savefig("XKCD_Colors.png")
  55. plt.show()

List of named colors

This plots a list of the named colors supported in matplotlib. Note that xkcd colors are supported as well, but are not listed here for brevity.

For more information on colors in matplotlib see

参考:List of named colors

参考:matplotlib

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/150987?site
推荐阅读
相关标签
  

闽ICP备14008679号