如何用曲线图自动设置轴线?Sns.kdeplot [英] How to automatically set the axes with the plot? sns.kdeplot

查看:40
本文介绍了如何用曲线图自动设置轴线?Sns.kdeplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用现场绘图配置绘图图像。 数据提供程序使用度量值x=105和y=68。

即使在这张图片中,您也可以看到进球是越界的。

matplotsoccer.field('white',figsize=10, show=False)
    
#Tidy Axes
plt.axis('Off')
   
    sns.kdeplot(df_acciones_ataque["x"],df_acciones_ataque["y"],n_levels=50, shade="True",cmap = 'coolwarm')
    
plt.ylim(0, 68)
plt.xlim(0,105)
    
#plt.suptitle("Acciones de Contraataques y Ataque Elaborado", fontsize=12)
plt.tight_layout(pad=0, w_pad=0, h_pad=0)
#plt.subplots_adjust(top=0.95)
    
    
#Display Pitch
plt.show()

推荐答案

对于2D kdedet,Seborn从给定的数据点中选择限制。在最新版本(现在是0.11.1)中,您可以设置阈值(thres=)以防止绘制最低层。设置thres=0将绘制所有层;最佳值取决于数据和要显示的内容。在旧版本中,可以使用shade_lowest=False

除此之外,还有clim,它限制了区域(但不能使其更大)。要将图像很好地填充到所需区域,可以同时使用clim和显式添加一个带有最低级别颜色的矩形:

import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
import numpy as np
import seaborn as sns

np.random.seed(1234)
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(18, 5))
for ax in (ax1, ax2, ax3):
    ax.plot([0, 0, 105, 105, 0], [0, 68, 68, 0, 0], color='black')
    ax.plot([105 / 2, 105 / 2], [0, 68], color='black')
    ax.add_patch(plt.Circle((105 / 2, 68 / 2), 9.15, fc='none', ec='black'))
    ax.set_aspect('equal')
    cmap = plt.cm.get_cmap('coolwarm')
    sns.kdeplot(x=np.random.normal(105 / 2, 12, 200), y=np.random.normal(68 / 2, 8, 200), n_levels=50,
                shade="True", cmap=cmap, clip=((0, 105), (0, 68)), thresh=0 if ax == ax1 else 0.002, ax=ax)
    ax.set_xlim(-2, 107)
    ax.set_ylim(-2, 70)
ax1.set_title('drawing the zero level')
ax2.set_title('without drawing the zero level')
ax3.add_patch(Rectangle((0, 0), 105, 68, ec='none', fc=cmap(0), zorder=0))
ax3.set_title('adding a rectangle for the zero level')
plt.show()

这篇关于如何用曲线图自动设置轴线?Sns.kdeplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆