因此,似乎一个不能执行以下操作(它产生一个错误,因为axes不具有set_linewidth法):

axes_style = {'linewidth':5}
axes_rect = [0.1, 0.1, 0.9, 0.9]

axes(axes_rect, **axes_style)

和具有使用以下旧特技代替:

rcParams['axes.linewidth'] = 5 # set the value globally

... # some code

rcdefaults() # restore [global] defaults

有一种简单的/清洁方式(可以是一个可以单独设置x-和y-轴参数等)?

P.S。如果没有,为什么?

有帮助吗?

解决方案

以上回答不工作,因为它是在评论说明。我建议使用棘。

import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

# you can change each line separately, like:
#ax.spines['right'].set_linewidth(0.5)
# to change all, just write:

for axis in ['top','bottom','left','right']:
  ax.spines[axis].set_linewidth(0.5)

plt.show()
# see more about spines at:
#http://matplotlib.org/api/spines_api.html
#http://matplotlib.org/examples/pylab_examples/multiple_yaxis_with_spines.html

其他提示

plt.setp(ax.spines.values(), linewidth=5)

是的,有一个简单,干净的方式来做到这一点。

从轴实例

调用 '的 axhline ' 和 '<强> axvline ' 看来是在MPL文档认可的技术。

在任何情况下,它是简单的和可以提供对轴的外观细粒度控制。

因此,例如,该代码将创建的曲线图和颜色X轴绿色和增加x轴的线宽度从“1”的默认值到“4”的值; y轴被标记为红色和y轴的线宽度从“1”增加至“8”。

from matplotlib import pyplot as PLT
fig = PLT.figure()
ax1 = fig.add_subplot(111)

ax1.axhline(linewidth=4, color="g")        # inc. width of x-axis and color it green
ax1.axvline(linewidth=4, color="r")        # inc. width of y-axis and color it red

PLT.show()

在axhline / axvline函数接受额外的参数,其应该以允许这样做任何几乎任何你想要美观,特别是任何的〜matplotlib.lines.Line2D属性都是有效kwargs(例如,“阿尔法”,“线型” ,capstyle,joinstyle)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top