How to automatically set the axes with the plot? sns.kdeplot(如何用曲线图自动设置轴线?Sns.kdeplot)
本文介绍了如何用曲线图自动设置轴线?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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何用曲线图自动设置轴线?Sns.kdeplot


基础教程推荐
猜你喜欢
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01