实现这种形式的图形,可通过matplotlib和pandas的实现,相比下pandas实现方便的多。

我数据分析的时候主要是stacked bar、bar和line形式的放在一张图上。stacked bar若用matplotlib实现的话会比较复杂(多组)

先上图吧

def plot_stacked_bar(left_data, right_data):
width = .3
axe = plt.subplot(111)
axe = left_data.plot(kind='bar', stacked=True, ax=axe, width=width, use_index=True, legend=False)
axe.set_xticklabels(left_data.index, rotation=0) #add patches to the stacked bar
patterns = ('-', '+', 'x', '\\', '*', 'o', 'O', '.', '/')
bars = axe.patches
hatches = ''.join(h*len(left_data) for h in patterns)
for bar, hatch in zip(bars, hatches):
bar.set_hatch(hatch) #plottint the line sharing the same x-axis on the secondary y-axis
axf = axe.twinx()
axf.plot(axe.get_xticks(), right_data, linestyle='-', marker='o', linewidth=2.0)
axf.set_ylim((0, 90))

另一种形式的图形:

from matplotlib import pyplot as plt
import pandas as pd
from pandas import Series
import numpy as np
n = 50
x = pd.period_range('2001-01-01', periods=n, freq='M')
y1 = (Series(np.random.randn(n)) + 5).tolist()
y2 = (Series(np.random.randn(n))).tolist()
df = pd.DataFrame({'bar':y2, 'line':y1}, index=x) # let's plot
plt.figure(figsize=(20, 4))
ax1 = df['bar'].plot(kind='bar', label='bar')
ax2 = ax1.twiny()
df['line'].plot(kind='line', label='line', ax=ax2)
ax2.grid(color="red", axis="x") def align_xaxis(ax2, ax1, x1, x2):
"maps xlim of ax2 to x1 and x2 in ax1"
(x1, _), (x2, _) = ax2.transData.inverted().transform(ax1.transData.transform([[x1, 0], [x2, 0]]))
xs, xe = ax2.get_xlim()
k, b = np.polyfit([x1, x2], [xs, xe], 1)
ax2.set_xlim(xs*k+b, xe*k+b) align_xaxis(ax2, ax1, 0, n-1)

#参考#

最新文章

  1. Access restriction: The type QName is not accessible due to restriction on required library
  2. python实现查看目录下重复的文件
  3. 【追寻javascript高手之路01】javascript参数知多少?
  4. Sql Server2005新特性及性能
  5. GCD中的dispatch_set_target_queue的用法及作用
  6. .ascx.g.cs文件不能生成 The name ‘InitializeControl’ does not exist in the current context - Visual Web part Sharepoint
  7. Java对信号的处理
  8. 数据校验validator 与 DWZ
  9. 020自动化测试 PK 手动测试
  10. perl正则表达式第三周笔记
  11. 操作数组的工具类Arrays
  12. 【Ruby】Ruby的model学习——Active Record Associations
  13. Scala - 快速学习03 - 基础语法
  14. Django之路由系统 Dj
  15. Qt__QMessageBox
  16. wireshark抓包的过滤规则
  17. 第8月第16天 django pil
  18. VREP中的二维激光雷达
  19. Object.getOwnPropertyNames和Object.keys
  20. Java Language Keywords

热门文章

  1. 62. Unique Paths (走棋盘多少种不同的走法 动态规划)
  2. android线程学习心得
  3. RBAC权限模型——项目实战
  4. PHP中构造函数和析构函数解析
  5. 从零开始玩转JMX(三)——Model MBean
  6. mysql索引的建立和使用
  7. [小问题笔记(六)] 解决JS已执行,输出内容乱码问题. 顺带总结编码相关知识
  8. Gogeos安装
  9. 关于Spring Test 小结
  10. Android开发-ADT Bundle安装