![](/img/trans.png)
[英]How to change scatter point size on Seaborn's relplot (seaborn.relplot not regplot)? Seaborn 0.9.0
[英]how to change limit between axis range in seaborn.relplot
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
d = {'x-axis':[100,915,298,299], 'y-axis': [1515,1450,1313,1315],
'text':['point1','point2','point3','point4']}
df = pd.DataFrame(d)
p1 = sns.relplot(x='x-axis', y='y-axis',data=df )
ax = p1.axes[0,0]
for idx,row in df.iterrows():
x = row[0]
y = row[1]
text = row[2]
ax.text(x+.05,y,text, horizontalalignment='left')
plt.show()
在这里我如何决定 x 轴范围。 我的意思是我希望 x 轴应该是 0 50 100 150 等,我希望 yaxis 是 0 500 1000 1500 等,而且我要确保两个轴都从 0 开始
您可以执行以下操作 - 使用该行
p1.set(xticks=[i for i in range(0, max(df['x-axis']) + 50, 50)],
yticks=[i for i in range(0, max(df['y-axis']) + 500, 500)])
动态设置刻度。
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
d = {'x-axis':[100,915,298,299], 'y-axis': [1515,1450,1313,1315],
'text':['point1','point2','point3','point4']}
df = pd.DataFrame(d)
p1 = sns.relplot(x='x-axis', y='y-axis',data=df )
ax = p1.axes[0,0]
for idx,row in df.iterrows():
x = row[0]
y = row[1]
text = row[2]
ax.text(x+.05,y,text, horizontalalignment='left')
p1.set(xticks=[i for i in range(0, max(df['x-axis']) + 50, 50)],
yticks=[i for i in range(0, max(df['y-axis']) + 500, 500)])
plt.show()
要增加 plot 的高度和宽度,使点不重叠,只需将这条线从
p1 = sns.relplot(x='x-axis', y='y-axis', data=df)
至
p1 = sns.relplot(x='x-axis', y='y-axis', data=df, height=10, aspect=1)
您可以根据需要更改height
和aspect
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.