python - 用于多变量绘图的 Python Matplotlib/Seaborn 模板
解决方案
看起来没有可用的 seaborn 模板,但您可以使用 matplotlib 子图和注释来生成类似的图。
我认为一般的方法是填充所有曲线之间的区域,并注释最小值和最大值。这是使用具有不同标准偏差的高斯曲线生成中间子图的示例。
import pandas as pd
import numpy as np
from scipy.signal.windows import gaussian
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
## create some simple gaussian curves
x = pd.date_range("2020-01-01", "2020-12-31", freq="D")
y_curves = [gaussian(len(x), std=s) for s in [40,80,120,160]]
colors = ["OrangeRed","Orchid","PeachPuff","LightGoldenRodYellow"]
y_max = max([max(y) for y in y_curves])
## loop through pairs of curves, filling between them
for i, y in enumerate(y_curves):
if i == 0:
plt.fill_between(x,y,color=colors[i])
elif i == 2:
plt.plot(x, y, color="black", linewidth=0.5)
plt.fill_between(x,y,y_curves[i-1],color=colors[i])
## annotate max value
y_max = max(y)
y_max_idx = y.tolist().index(max(y))
x_max = x[y_max_idx]
plt.annotate(text="muggy: 100%", xy=(x_max, y_max-0.05))
else:
plt.fill_between(x,y,y_curves[i-1],color=colors[i])
# Set the locator
locator = mdates.MonthLocator() # every month
# Specify the format - %b gives us Jan, Feb...
fmt = mdates.DateFormatter('%b')
X = plt.gca().xaxis
X.set_major_locator(locator)
# Specify formatter
X.set_major_formatter(fmt)
plt.xlim([x[0], x[-1]])
plt.ylim([0, 1])
plt.show()
推荐阅读
- c++ - CascadeClassifier 未定义
- swift - Swift 中具有新泛型类型的泛型类型扩展
- parse-platform - 云代码:当我们将参数传递给查询时,我们是否需要转义参数?
- google-apps-script - 在单元格值更改上自动化脚本
- c++ - 向量的地址代表什么?
- mysql - MariaDB 10.3 - 布尔搜索为 Innodb 和 MyISAM 返回不同的结果
- sql - 为什么 QueryRow().Scan() 在表中不为空时返回空字符串?
- kubernetes - Helm/k8s 修改静态文件使用同一个容器镜像
- php - 使用递归函数构建引导程序 4 菜单
- javascript - 如何在 html 表中显示 php 响应的数据