Python matplotlib画图实例之绘制拥有彩条的图表

2019/7/13 22:28:09

本文主要是介绍Python matplotlib画图实例之绘制拥有彩条的图表,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

生产定制一个彩条标签。

首先导入:

import matplotlib.pyplot as plt
import numpy as np
from matplotlib import cm
from numpy.random import randn

制作拥有垂直(默认)彩条的图表:

fig, ax = plt.subplots()

data = np.clip(randn(250, 250), -1, 1)

cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)
ax.set_title('Gaussian noise with vertical colorbar')

# Add colorbar, make sure to specify tick locations to match desired ticklabels
cbar = fig.colorbar(cax, ticks=[-1, 0, 1])
cbar.ax.set_yticklabels(['< -1', '0', '> 1']) # vertically oriented colorbar

效果图:

制作拥有水平彩条的图表:

fig, ax = plt.subplots()

data = np.clip(randn(250, 250), -1, 1)

cax = ax.imshow(data, interpolation='nearest', cmap=cm.afmhot)
ax.set_title('Gaussian noise with horizontal colorbar')

cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal')
cbar.ax.set_xticklabels(['Low', 'Medium', 'High']) # horizontal colorbar

plt.show()

效果图:

脚本运行耗时:(0分0.075秒)

总结

以上就是本文关于Python matplotlib画图实例之绘制拥有彩条的图表的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!



这篇关于Python matplotlib画图实例之绘制拥有彩条的图表的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程