我想要只有左轴和下轴,而不是默认的"盒装"轴样式,即:
+------+ |
| | |
| | ---> |
| | |
+------+ +-------
Run Code Online (Sandbox Code Playgroud)
这应该很简单,但我在文档中找不到必要的选项.
由于它们是在绘图区域内绘制的,因此许多matplotlib图中的数据会使轴刻度变得模糊.更好的方法是绘制从轴向外延伸的刻度线,如ggplotR的绘图系统中的默认值.
从理论上讲,这可以通过重新绘制与所述刻度线来完成TICKDOWN和TICKLEFT线样式的x轴和y轴分别蜱:
import matplotlib.pyplot as plt
import matplotlib.ticker as mplticker
import matplotlib.lines as mpllines
# Create everything, plot some data stored in `x` and `y`
fig = plt.figure()
ax = fig.gca()
plt.plot(x, y)
# Set position and labels of major and minor ticks on the y-axis
# Ignore the details: the point is that there are both major and minor ticks
ax.yaxis.set_major_locator(mplticker.MultipleLocator(1.0))
ax.yaxis.set_minor_locator(mplticker.MultipleLocator(0.5))
ax.xaxis.set_major_locator(mplticker.MultipleLocator(1.0))
ax.xaxis.set_minor_locator(mplticker.MultipleLocator(0.5))
# Try to set the tick markers …Run Code Online (Sandbox Code Playgroud)