[英]How to use matplotlib to plot complex bar graphs–multiple subplots with multiple rows of bars?
您可以使用bar
的bottom
参数来偏移各个行。
以下未优化的示例演示了这种方法:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
df = pd.DataFrame(np.random.randint(0, 10, size=(1000, 11)), columns=list('ABCDEFGHIJK'))
fig = plt.figure()
for i,c in enumerate(df.columns):
ax = fig.add_subplot(3, 4, i+1)
for x,h,b in zip((df.index.to_numpy() % 200).reshape(-1, 200), df[c].to_numpy().reshape(-1, 200), (df.index.to_numpy() // 200 * 10).reshape(-1, 200)):
ax.set_title(c)
ax.bar(x, h, bottom=b, color='k' )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.