matplotlib - 使用 matplotlib 突出显示堆栈图区域
问题描述
我想在堆栈图中突出显示一个堆栈的区域,例如 x 轴上的区域 4-5B
仅使用另一种颜色或散列:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y1 = [1, 1, 2, 3, 5]
y2 = [0, 4, 2, 6, 8]
labels = ['A', 'B']
fig, ax = plt.subplots()
ax.stackplot(x, y1, y2, labels=labels)
ax.legend()
解决方案
手动添加的多边形。这可以同时着色和孵化。
import matplotlib.pyplot as plt
import matplotlib.patches as patches
x = [1, 2, 3, 4, 5]
y1 = [1, 1, 2, 3, 5]
y2 = [0, 4, 2, 6, 8]
labels = ['A', 'B']
fig, ax = plt.subplots()
ax.stackplot(x, y1, y2, labels=labels)
p = patches.Polygon(((4.0, 3.0),(5.0,4.0),(5.0,13.0),(4.0,9.0)), fc='g', hatch='x')
ax.add_patch(p)
ax.legend()
推荐阅读
- mysql - 安装后步骤未成功完成 MySQL Mac OS Sierra
- swift - FirebaseDatabase runTransaction 块问题
- maven - maven-compiler-plugin 用 jar 库编译项目
- selenium-webdriver - SlickGrid Selenium 自动化问题
- javascript - 此 Funnelytics 代码是否包含竞争条件?
- php - 我的代码有什么问题?被重定向到同一页面
- linux - 如何在bash中打印包含特定单词的特定行
- r - 根据R中的条件合并数据框中的多列
- c# - WPF - 具有命令绑定的全局上下文菜单
- c# - 尝试使用 EPPlus 从 ZipArchive 读取 Excel 文件