作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想让我的轴通过散点图中的原点 (0,0),这就是我在下面的示例中设置脊柱位置的原因。问题是我在散点图上的实际数据点覆盖了轴刻度标签,因此看不到它们。
如何让 matplotlib 使用我的轴刻度标签“覆盖”数据点,以便可以看到它们?
import numpy as np
from matplotlib import pyplot as plt
plt.style.use('ggplot')
x = np.random.randn(5000)
y = np.random.randn(5000)
f, ax = plt.subplots()
plt.scatter(x,y)
ax.spines['left'].set_position('zero')
ax.spines['left'].set_color('black')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['bottom'].set_color('black')
ax.spines['top'].set_color('none')
plt.show()
最佳答案
您可以通过设置 zorder
来解决这个问题分散到某物上 <0
例如:
plt.scatter(x,y,zorder=-5)
不幸的是,即便如此,它们在 ggplot
中也不是很明显。风格:
如果更改散点图和标签的颜色(请注意,下图中标签明显位于散点图上方),您可以更清楚地看到这一点,因此您可能需要试验才能找到自己喜欢的东西
ax.tick_params(labelcolor='r')
plt.scatter(x,y,color='w',zorder=-5)
关于python - 散点图覆盖的 matplotlib 轴刻度标签(使用脊柱),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32652673/
我是一名优秀的程序员,十分优秀!