seaborn(python)中具有多个带宽的打印线
在seaborn中,是否也有一种方法可以使用带宽制作线条图?Lineplot具有显示置信区间的选项(另请参见:和文档)。或者有人会建议我用精心设计的/不同的软件包来做这件事吗 但我想要的是用一个信号画一条线,并用填充颜色在它周围画几个带(当带离信号越远时,透明度越高) 基于这个主题,我在Matplotlib中做了一些事情:seaborn(python)中具有多个带宽的打印线,python,python-3.x,matplotlib,seaborn,Python,Python 3.x,Matplotlib,Seaborn,在seaborn中,是否也有一种方法可以使用带宽制作线条图?Lineplot具有显示置信区间的选项(另请参见:和文档)。或者有人会建议我用精心设计的/不同的软件包来做这件事吗 但我想要的是用一个信号画一条线,并用填充颜色在它周围画几个带(当带离信号越远时,透明度越高) 基于这个主题,我在Matplotlib中做了一些事情: # Imports import pandas as pd import numpy as np import matplotlib.pyplot as plt import
# Imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.lines as mlines
# Create dataset
mean = np.random.randint(1,101,24)
max_val = np.random.randint(101,150,24)
min_val = np.random.randint(-50,1,24)
std = np.random.randint(10,30,24)
df = pd.DataFrame({'min': min_val,
'-3std': -3*std+mean,
'-2std': -2*std+mean,
'-1std': -1*std+mean,
'mean': mean,
'1std': 1*std+mean,
'2std': 2*std+mean,
'3std': 3*std+mean,
'max':max_val})
# function for plot
def plot_bandwidth(df, set_labels=True, colortone='blue', ax=None, show=False):
"""
Method to create a plot from a dataframe with the required columns [] and index
:param (pd.DataFrame) df: Dataframe with numeric values
:param (bool) set_labels: Boolean value to choose if labels are shown
:param (string) colortone: String with the color to use as base for different lines/areas
:param (ax) ax: Option to add axes to combine multiple plots
:param (bool) show: Boolean to show plot or return figure
:return plot/fig
"""
# TODO: Assert if required columns not available
if not ax:
_, ax = plt.subplots()
quarters_of_day = df.index
ax.plot(quarters_of_day, df['mean'], color=colortone)
ax.fill_between(quarters_of_day, df['-3std'], df['3std'], alpha=.1, color=colortone)
ax.fill_between(quarters_of_day, df['-2std'], df['2std'], alpha=.1, color=colortone)
ax.fill_between(quarters_of_day, df['-1std'], df['1std'], alpha=.1, color=colortone)
ax.plot(quarters_of_day, df['min'], color='dark'+colortone, ls='--', alpha=.4)
ax.plot(quarters_of_day, df['max'], color='dark'+colortone, ls='--', alpha=.4)
if set_labels == True:
ax.set_title("Example plot")
ax.set_xlabel("Hour")
ax.set_ylabel("Value")
legend_mean = mlines.Line2D([], [], color=colortone, label='Mean')
legend_bandwidth_std1 = mpatches.Patch(alpha=.3, color=colortone, label='Bandwidth of 1 sigma')
legend_bandwidth_std2 = mpatches.Patch(alpha=.2, color=colortone, label='Bandwidth of 2 sigma')
legend_bandwidth_std3 = mpatches.Patch(alpha=.1, color=colortone, label='Bandwidth of 3 sigma')
legend_minmax = mlines.Line2D([], [], color='dark'+colortone, ls='--', alpha=.4, label='Minimum or Maximum')
plt.legend(handles=[legend_mean, legend_bandwidth_std1, legend_bandwidth_std2, legend_bandwidth_std3, legend_minmax], loc='center left', bbox_to_anchor=(1, 0.5))
if show:
return plt.show()
plot_bandwidth(df)
这导致了这样一个情节:
@Yatin这是我的第一篇文章,作为一个新的投稿人,你还没有这个选择。我认为你不能仅仅使用
seaborn.lineplot
。然而,seaborn本质上只是matplotlib的包装器。因此,您可以使用seaborn的lineplot
,也可以在seaborn绘制的轴上执行ax.fill\u。