相关疑难解决方法(0)

如何在matplotlib中删除顶部和右侧轴?

我想要只有左轴和下轴,而不是默认的"盒装"轴样式,即:

+------+         |
|      |         |
|      |   --->  |
|      |         |
+------+         +-------
Run Code Online (Sandbox Code Playgroud)

这应该很简单,但我在文档中找不到必要的选项.

python matplotlib

105
推荐指数
7
解决办法
8万
查看次数

在matplotlib中,如何绘制从轴向外指向的R样式轴刻度?

由于它们是在绘图区域内绘制的,因此许多matplotlib图中的数据会使轴刻度变得模糊.更好的方法是绘制从轴向延伸的刻度线,如ggplotR的绘图系统中的默认值.

从理论上讲,这可以通过重新绘制与所述刻度线来完成TICKDOWNTICKLEFT线样式的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)

python plot matplotlib

20
推荐指数
1
解决办法
6873
查看次数

标签 统计

matplotlib ×2

python ×2

plot ×1