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中内置的User模型实例详解

User模型 User模型是这个框架的核心部分。他的完整的路径是在django.contrib.auth.models.User。 字段 内置的User模型拥有以下的字段: 1、us...

Python命令行解析模块详解

本文研究的主要是Python命令行解析模块的相关内容,具体如下。 Python命令行常见的解析器有两种,一是getopt模块,二是argparse模块。下面就解读下这两种解析器。 ge...

fastcgi文件读取漏洞之python扫描脚本

fastcgi文件读取漏洞之python扫描脚本

PHP FastCGI的远程利用 说到FastCGI,大家都知道这是目前最常见的webserver动态脚本执行模型之一。目前基本所有web脚本都基本支持这种模式,甚至有的类型脚本这是唯一...

python 搭建简单的http server,可直接post文件的实例

server: #coding=utf-8 from BaseHTTPServer import BaseHTTPRequestHandler import cgi class Po...

python 调试冷知识(小结)

python 调试冷知识(小结)

对于 python 代码的调试我们通常都是使用 IDE 自带的调试功能。但是 IDE 提供的调试功能存在局限性,例如在测试服务器上调试代码,但是又不可能在测试服务器上安装 IDE 进行调...