细化 X 轴,以便更好地识别距离
Refine X- Axis so that the distances are better recognizable
我有问题。我有一个数据框 df
。我想在 seaborn 的帮助下绘制散点图。但我想改变 x 轴。我希望 x 轴从 4.0 到 5.0 更精细。距离应该更小,例如4.1、4.2 甚至更好。
我如何设置才能使 x 轴显示更精细,以便我可以更好地看到 4.0 的值?
我看了seaborn, pylab - changing xticks from float to int , How to change the X axis range in seaborn in python?
d = {'review_scores_accuracy': [1.1, 2.0, 4.5, 5.0, 4.9, 4.8, 4.7],
'review_scores_rating': [1.1, 2.0, 4.6, 3.9, 4.2, 4.5, 4.2]}
df = pd.DataFrame(data=d)
fig, ax = plt.subplots(figsize=(20,10))
sns.scatterplot(data=df, x="review_scores_rating", y="review_scores_accuracy", ax = ax )
# ax.set_xlim(1,5)
# ax.set_xticks(1,2,3,4,4.1,4.2)
plt.show()
根据
使用matplotlib.ticker
import pandas as pd
import seaborn as sns
import matplotlib.ticker as ticker
d = {'review_scores_accuracy': [1.1, 2.0, 4.5, 5.0, 4.9, 4.8, 4.7],
'review_scores_rating': [1.1, 2.0, 4.6, 3.9, 4.2, 4.5, 4.2]}
df = pd.DataFrame(data=d)
fig, ax = plt.subplots(figsize=(20,10))
sns.scatterplot(data=df, x="review_scores_rating",y="review_scores_accuracy", ax=ax)
ax.xaxis.set_major_locator(ticker.MultipleLocator(0.1))
plt.show()
如果您只想在 4 和 5 之间绘图,请缩小数据范围。
我有问题。我有一个数据框 df
。我想在 seaborn 的帮助下绘制散点图。但我想改变 x 轴。我希望 x 轴从 4.0 到 5.0 更精细。距离应该更小,例如4.1、4.2 甚至更好。
我如何设置才能使 x 轴显示更精细,以便我可以更好地看到 4.0 的值?
我看了seaborn, pylab - changing xticks from float to int , How to change the X axis range in seaborn in python?
d = {'review_scores_accuracy': [1.1, 2.0, 4.5, 5.0, 4.9, 4.8, 4.7],
'review_scores_rating': [1.1, 2.0, 4.6, 3.9, 4.2, 4.5, 4.2]}
df = pd.DataFrame(data=d)
fig, ax = plt.subplots(figsize=(20,10))
sns.scatterplot(data=df, x="review_scores_rating", y="review_scores_accuracy", ax = ax )
# ax.set_xlim(1,5)
# ax.set_xticks(1,2,3,4,4.1,4.2)
plt.show()
根据
matplotlib.ticker
import pandas as pd
import seaborn as sns
import matplotlib.ticker as ticker
d = {'review_scores_accuracy': [1.1, 2.0, 4.5, 5.0, 4.9, 4.8, 4.7],
'review_scores_rating': [1.1, 2.0, 4.6, 3.9, 4.2, 4.5, 4.2]}
df = pd.DataFrame(data=d)
fig, ax = plt.subplots(figsize=(20,10))
sns.scatterplot(data=df, x="review_scores_rating",y="review_scores_accuracy", ax=ax)
ax.xaxis.set_major_locator(ticker.MultipleLocator(0.1))
plt.show()
如果您只想在 4 和 5 之间绘图,请缩小数据范围。