在python ggplot中调整坐标轴范围和刻度标记

14 投票
1 回答
3433 浏览
提问于 2025-04-18 05:53

有没有办法在使用Python的ggplot画散点图时,同时设置坐标轴的范围和刻度的数量?比如,我想把y轴设置为从0到100,并且在0、10、20、30……100这些值上有刻度。

我试过以下方法:

ggplot(aes(x=x, y=y), data=data) + geom_point() + scale_y_continuous(limits=(0,100), breaks=range(0,100,10))
ggplot(aes(x=x, y=y), data=data) + geom_point() + scale_y_continuous(breaks=range(0,100,10)) + ylim(0,100)
ggplot(aes(x=x, y=y), data=data) + geom_point() + scale_y_continuous(breaks=range(0,100,10))

在前两行代码中,设置的范围覆盖了刻度,所以我得到了一个从0到100的坐标轴,但刻度却没有出现。在最后一行代码中,刻度是出现了,但范围却只是ggplot根据数据自动生成的,而不是我想要的0到100的范围。

1 个回答

1

这里描述的问题现在无法重现。可以使用ggplot 0.11.5来解决这个问题。

撰写回答