How to set limits and margins in scatterplot matplotlib?

问题描述 投票:0回答:0

我有散点图的代码

import matplotlib.pyplot as plt
%matplotlib inline
from matplotlib import style
style.use('ggplot')
plt.figure(figsize=(5,5))

x = merged_rizvan['rating.mean']
y = merged_rizvan['female_prob']
colors = ['blue', 'green']


fig, ax = plt.subplots()


ax.scatter(x, y)

ax.set_xlim(-50, 50)
ax.set_ylim(0,1)
ax.set_xlabel("Rating Mean \n (people's intuitions)")
ax.set_ylabel("Female Probability \n (classifier predictions)")
ax.legend()

#fig.text(0.05, 0.95, "Female", ha='left', va='top', fontsize=10)
fig.text(0.07, 0.05, "Male", ha='left', va='bottom', fontsize=10)
fig.text(0.90, 0.05, 'Female', ha='left', va='bottom', fontsize=10)

plt.xticks([-50, 0, 50])
plt.show()

但结果并不是我想要的。有一些数据点非常接近 50 和 -50,所以它们基本上超出了绘图范围。

scatterplot

我需要一些边距,同时保持 xlim 和 ylim(所以基本上我想仍然可视化 -50 和 50)但是当我尝试添加边距时它没有正确改变。除此之外,我想添加“女性”和“男性”而不是 -50 和 50。你有什么建议吗?

python matplotlib scatter-plot
© www.soinside.com 2019 - 2024. All rights reserved.