使用Matplotlib画图

使用Matplotlib画图

步骤:

1.创建画板:figure

import matplotlib.pyplot as plt
fig = plt.figure()

2.x,y 坐标轴:add_subplot

ax = fig.add_subplot(2, 2, 1)
# do something 放入点、线、柱等等等

3.显示:show

plt.show()

使用Series、DataFrame转换图像

1.Series

  • Series是什么?

有索引的数据列表,可根据索引来查询值,可轻松展示为空与否,也可进行Series的计算。

import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(10).cumsum(), index=np.arange(0, 100, 10))
s.plot()
plt.show()

2.DataFrame

  • DataFrame是什么?

表格型数据结构,有行、列概念。含一组有序的列,每列可看成是一个Series。
如何进行索引?frame['column_name'] = 列索引、frame.ix['row_name'] = 行索引

df = pd.DataFrame(np.random.randn(10, 4).cumsum(0), columns=['A', 'B', 'C', 'D'], index=np.arange(0, 100, 10))
df.plot(kind='bar', stacked=True)
plt.show()
原文地址:https://www.cnblogs.com/alben/p/6605979.html