python可视化:matplotlib系列

matplotlib 的官方文档:

https://matplotlib.org/users/index.html

1 子图布局管理

布局参数

紧密布局的方法

坐标轴的公用和隐藏

2 直方图bar和barh的使用

主要参数

颜色参数

堆积图

3 简单示例(筹码分布图)

#%% 筹码分布图
import mpl_finance as mpf
import matplotlib.pyplot as plt

pricelst = sorted(set(list(cdata['close'])))
volumelst = []
moneylst = []
for i in pricelst:
    volumelst.append(cdata[cdata['close'] == i]['volume'].sum())
    moneylst.append(cdata[cdata['close'] == i]['money'].sum())
# 绘制
fig = plt.figure(figsize=(30, 10),dpi=100)
ax1 = plt.subplot2grid((1, 4), (0, 0))
ax2 = plt.subplot2grid((1, 4), (0, 1), colspan=3,sharey=ax1)
xlabel = pricelst
ax1.barh(xlabel,moneylst,height=0.5,alpha=0.8) # 直方图
mpf.candlestick2_ochl(ax2,hdata['open'],hdata['close'],hdata['high'],hdata['low'],
                      width=0.5, colorup='red', colordown='green',alpha=1) # K线图
ax2.axes.get_yaxis().set_visible(False)#y轴不可见
plt.subplots_adjust(wspace =0, hspace =0)#调整子图间距

猜你喜欢

转载自www.cnblogs.com/JuliaZhao/p/12034202.html