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绘制精美的条形统计图的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

相关文章

numpy linalg模块的具体使用方法

最近在看机器学习的 LogisticRegressor,BayesianLogisticRegressor算法,里面得到一阶导数矩阵g和二阶导数Hessian矩阵H的时候,用到...

详解Python中的变量及其命名和打印

在程序中,变量就是一个名称,让我们更加方便记忆。 cars = 100 space_in_a_car = 4.0 drivers = 30 passengers = 90...

Python散点图与折线图绘制过程解析

Python散点图与折线图绘制过程解析

这篇文章主要介绍了Python散点图与折线图绘制过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 在数据分析的过程中,经常需要将...

Python数据分析库pandas基本操作方法

Python数据分析库pandas基本操作方法

pandas是什么? 是它吗? 。。。。很显然pandas没有这个家伙那么可爱。。。。 我们来看看pandas的官网是怎么来定义自己的: pandas is an open sourc...

Python数据结构与算法之图的最短路径(Dijkstra算法)完整实例

Python数据结构与算法之图的最短路径(Dijkstra算法)完整实例

本文实例讲述了Python数据结构与算法之图的最短路径(Dijkstra算法)。分享给大家供大家参考,具体如下: # coding:utf-8 # Dijkstra算法——通过边实现...