![](/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.