Python 打印平滑matplotlib和seaborn
我试图以一种良好的方式显示我的数据,如seaborn文档中所示: 我不太清楚该如何进行。我设法得到了点的值和它们各自的标准偏差,但它看起来很分散,而我只是想展示一种趋势: 我研究并尝试应用建议的解决方案,但我无法使其起作用 以下是我玩的游戏:Python 打印平滑matplotlib和seaborn,python,matplotlib,seaborn,smoothing,Python,Matplotlib,Seaborn,Smoothing,我试图以一种良好的方式显示我的数据,如seaborn文档中所示: 我不太清楚该如何进行。我设法得到了点的值和它们各自的标准偏差,但它看起来很分散,而我只是想展示一种趋势: 我研究并尝试应用建议的解决方案,但我无法使其起作用 以下是我玩的游戏: Final_array = Mean Std 0 0.739269 0.157892 1 0.807382 0.160464 2 0.800024 0.137239 3 0.825854 0.1324
Final_array = Mean Std
0 0.739269 0.157892
1 0.807382 0.160464
2 0.800024 0.137239
3 0.825854 0.132472
4 0.864854 0.070544
.. ... ...
95 0.797202 0.101961
96 0.747578 0.143394
97 0.751472 0.158651
98 0.587009 0.198987
99 0.728447 0.104601
sns.set(style="darkgrid", palette="muted", color_codes=True)
fig, ax = plt.subplots(figsize=(7,5))
y_pos = np.arange(Final_array.shape[0])
ax.errorbar(y_pos, Final_array[:,0], yerr=Final_array[:,1], elinewidth=0.5)
plt.show()
有人有主意吗?我在使用情节方面是个新手。有没有可能把它弄平?得到seaborn图像中的漂亮覆盖,而不是错误条
这些可能是愚蠢的问题
您好,您可以使用
fillbetween
来平滑上下曲线。选择更高的sigma
将提供更高的平滑度
下面是一些示例代码:
导入matplotlib.pyplot作为plt
将numpy作为np导入
从scipy.ndimage.filters导入高斯滤波器1d
x=np.linspace(0,100100)
y=0.95-((50-x)/200)**2
误差=(1-y)/2
y+=np.随机.正常(0,误差/10,y.大小)
上限=高斯滤波器1d(y+误差,σ=3)
下限=高斯滤波器1d(y-误差,σ=3)
图,ax=plt子批次(ncols=2)
ax[0]。错误条(x,y,err,color='dodgerblue')
ax[1]。绘图(x,y,color='dodgerblue')
ax[1]。在(x,上,下,颜色为深红色,alpha=0.2)之间填充
plt.show()
对于平滑的上下曲线,可以使用
fillbetween
。选择更高的sigma
将提供更高的平滑度
下面是一些示例代码:
导入matplotlib.pyplot作为plt
将numpy作为np导入
从scipy.ndimage.filters导入高斯滤波器1d
x=np.linspace(0,100100)
y=0.95-((50-x)/200)**2
误差=(1-y)/2
y+=np.随机.正常(0,误差/10,y.大小)
上限=高斯滤波器1d(y+误差,σ=3)
下限=高斯滤波器1d(y-误差,σ=3)
图,ax=plt子批次(ncols=2)
ax[0]。错误条(x,y,err,color='dodgerblue')
ax[1]。绘图(x,y,color='dodgerblue')
ax[1]。在(x,上,下,颜色为深红色,alpha=0.2)之间填充
plt.show()
谢谢你的帮助!我成功地生成了我想要的图形 首先,样条线不起作用,因为我的数据没有排序。因此,我使用了由和提出的
gaussian_filter1d
。但是,很明显,它会改变数据(阅读注释),因此我决定将这两个图形一起绘制:
使用此最终版本:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.ndimage.filters import gaussian_filter1d
Final_array = Mean Std
0 0.739269 0.157892
1 0.807382 0.160464
2 0.800024 0.137239
3 0.825854 0.132472
4 0.864854 0.070544
.. ... ...
95 0.797202 0.101961
96 0.747578 0.143394
97 0.751472 0.158651
98 0.587009 0.198987
99 0.728447 0.104601
sns.set(style="darkgrid", palette="muted", color_codes=True)
fig, ax = plt.subplots(figsize=(7,5))
y_pos = np.arange(Final_array.shape[0])
# Smoothing
Final_array_smooth = gaussian_filter1d(Final_array[:,0], sigma=2)
# Error formating
upper_err = gaussian_filter1d(Final_array[:,0] + (Final_array[:,1]/2), sigma=5)
lower_err = gaussian_filter1d(Final_array[:,0] - (Final_array[:,1]/2), sigma=5)
ax.plot(y_pos, Final_array[:,0], '--', linewidth=0.7, color='k', alpha=0.45)
ax.plot(y_pos, Final_array_smooth)
ax.fill_between(y_pos, upper_err, lower_err, color='crimson', alpha=0.2)
ax.set_ylim(np.min(Final_array[:,0])-(np.min((Final_array[:,0])*20)/100), np.max(Final_array[:,0])+(np.max((Final_array[:,0])*10)/100))
plt.show()
多谢各位 谢谢你的帮助!我成功地生成了我想要的图形 首先,样条线不起作用,因为我的数据没有排序。因此,我使用了由和提出的
gaussian_filter1d
。但是,很明显,它会改变数据(阅读注释),因此我决定将这两个图形一起绘制:
使用此最终版本:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.ndimage.filters import gaussian_filter1d
Final_array = Mean Std
0 0.739269 0.157892
1 0.807382 0.160464
2 0.800024 0.137239
3 0.825854 0.132472
4 0.864854 0.070544
.. ... ...
95 0.797202 0.101961
96 0.747578 0.143394
97 0.751472 0.158651
98 0.587009 0.198987
99 0.728447 0.104601
sns.set(style="darkgrid", palette="muted", color_codes=True)
fig, ax = plt.subplots(figsize=(7,5))
y_pos = np.arange(Final_array.shape[0])
# Smoothing
Final_array_smooth = gaussian_filter1d(Final_array[:,0], sigma=2)
# Error formating
upper_err = gaussian_filter1d(Final_array[:,0] + (Final_array[:,1]/2), sigma=5)
lower_err = gaussian_filter1d(Final_array[:,0] - (Final_array[:,1]/2), sigma=5)
ax.plot(y_pos, Final_array[:,0], '--', linewidth=0.7, color='k', alpha=0.45)
ax.plot(y_pos, Final_array_smooth)
ax.fill_between(y_pos, upper_err, lower_err, color='crimson', alpha=0.2)
ax.set_ylim(np.min(Final_array[:,0])-(np.min((Final_array[:,0])*20)/100), np.max(Final_array[:,0])+(np.max((Final_array[:,0])*10)/100))
plt.show()
多谢各位 为什么样条线解决方案不适用于您?因为我的数据未排序,我无法使用样条线进行平滑。为什么样条线解决方案不适用于您?因为我的数据未排序,我无法使用样条线进行平滑。