首页 > 解决方案 > 使用数据限制绘图(python)

问题描述

我想要这样的图,我不确定如何在 Y 轴上设置 UL 和 LL,如下图所示在 此处输入图像描述

请帮助设置限制,我使用 seaborn 包。

标签: pythonseaborn

解决方案


该图表称为控制图,可以使用库pyspc安装它来完成pip install pyspc

您可以使用这两行来添加显示一个限制

horiz_line_data = nnp.array([5 for i in range(len(x))])
plt.plot(x, horiz_line_data, 'r--')

这是示例代码

import matplotlib.pyplot as plt
import numpy as nnp
import seaborn as sns
from pyspc import *
sns.set()
plt.figure()
plt.plot([30, 50, 20, 10, 60])
x = [0,1,2,3,4]
LL=5
UL=75
horiz_line_data = nnp.array([LL for i in range(len(x))])
plt.plot(x, horiz_line_data, 'r--')
horiz_line_data = nnp.array([UL for i in range(len(x))])
plt.plot(x, horiz_line_data, 'r--')
plt.ylim((-10, 90))

图表看起来像 在此处输入图像描述


推荐阅读