Python+matplotlib+numpy绘制精美的条形统计图

yipeiwu_com6年前Python基础

本文实例主要向大家分享了一个Python+matplotlib+numpy绘制精美的条形统计图的代码,效果展示如下:

完整代码如下:

import matplotlib.pyplot as plt
from numpy import arange
from numpy.random import rand


def gbar(ax, x, y, width=0.5, bottom=0):
  X = [[.6, .6], [.7, .7]]
  for left, top in zip(x, y):
    right = left + width
    ax.imshow(X, interpolation='bicubic', cmap=plt.cm.Blues,
         extent=(left, right, bottom, top), alpha=1)


fig = plt.figure()

xmin, xmax = xlim = 0, 10
ymin, ymax = ylim = 0, 1
ax = fig.add_subplot(111, xlim=xlim, ylim=ylim,
           autoscale_on=False)
X = [[.6, .6], [.7, .7]]

ax.imshow(X, interpolation='bicubic', cmap=plt.cm.copper,
     extent=(xmin, xmax, ymin, ymax), alpha=1)

N = 10
x = arange(N) + 0.25
y = rand(N)
gbar(ax, x, y, width=0.7)
ax.set_aspect('auto')
plt.show()

总结

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

相关文章

Django上线部署之IIS的配置方法

环境: 1 .Windows Server 2016 Datacenter 64位 2 .SQL Server 2016 Enterprise 64位 3 .Python 3.6.0 6...

Python中字符串List按照长度排序

下面看下字符串List按照长度排序(python)的实现方法 myList = ['青海省','内蒙古自治区','西藏自治区','新疆维吾尔自治区','广西壮族自治区'] 1、首先得到每...

python中sort和sorted排序的实例方法

Python list内置sort()方法用来排序,也可以用python内置的全局sorted()方法来对可迭代的序列排序生成新的序列。 1)排序基础 简单的升序排序是非常容易的。只需要...

解决pycharm安装后代码区不能编辑的问题

解决pycharm安装后代码区不能编辑的问题

此问题是由于最新的pycharm在安装时自动装了vimVim插件 你可以在tools Vim emulator将对勾去掉就可以了。 以上这篇解决pycharm安装后代码区不能编辑的问题...

python sqlobject(mysql)中文乱码解决方法

UnicodeEncodeError: 'latin-1' codec can't encode characters in position; 找了一天终于搞明白了,默认情况下,mys...