设置axes.linewidth而不更改rcParams全局字典
,似乎无法执行以下操作(它会引发错误,因为 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 轴参数等)?
如果没有,为什么?
So, it seems one cannot do the following (it raises an error, since axes
does not have a set_linewidth
method):
axes_style = {'linewidth':5}
axes_rect = [0.1, 0.1, 0.9, 0.9]
axes(axes_rect, **axes_style)
and has to use the following old trick instead:
rcParams['axes.linewidth'] = 5 # set the value globally
... # some code
rcdefaults() # restore [global] defaults
Is there an easy / clean way (may be one can set x
- and y
- axes parameters individually, etc)?
If no, why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
spines
。spines
.是的,有一种简单而干净的方法可以做到这一点。
从轴实例调用“axhline”和“axvline”似乎是 MPL 文档中认可的技术。
无论如何,它都很简单,并且可以让您对轴的外观进行细粒度的控制。
例如,此代码将创建一个绘图并将 x 轴着色为绿色,并将 x 轴的线宽从默认值“1”增加到值“4”; y轴被涂成红色并且y轴的线宽从“1”增加到“8”。
axhline/axvline 函数接受额外的参数,这些参数应该允许您做任何您想要的美观的事情,特别是任何 ~matplotlib.lines.Line2D 属性都是有效的 kwargs(例如,'alpha','linestyle',capstyle,联合风格)。
Yes, there's an easy and clean way to do this.
Calling 'axhline' and 'axvline' from an axis instance appears to be the technique endorsed in the MPL Documentation.
In any event, it is simple and gives you fine-grained control over the appearance of the axes.
So for instance, this code will create a plot and color the x-axis green and increase the line width of the x-axis from a default value of "1" to a value of "4"; the y-axis is colored red and the line width of the y-axis is increased from "1" to "8".
The axhline/axvline function accepts additional arguments which ought to allow you do any pretty much whatever you want aesthetically, in particular any of the ~matplotlib.lines.Line2D properties are valid kwargs (e.g., 'alpha', 'linestyle', capstyle, joinstyle).
如果您使用 pyplot 递归创建(非矩形)轴,则可以更改每个轴的线宽参数。
例如:
有关文档,请参阅 MPL.axes 文档 (向下滚动直到“其他参数”-> **kwargs)
注意“如果使用一个绘图命令绘制多条线,则 kwargs 将应用于所有这些线。”
也许这个解决方案与其他地方提出的不同问题有关,但我发现这个页面正在寻找我自己问题的解决方案,所以也许它可以帮助其他人寻找相同的东西。
If you're recursively creating (non-rectangular) axes using pyplot, you can change the linewidth parameter for each ax.
For instance:
For documentation, see MPL.axes documentation (Scroll down until "Other Parameters" -> **kwargs)
N.B. "If you make multiple lines with one plot command, the kwargs apply to all those lines."
Maybe this solution is related to a different question asked elsewhere, but I found this page looking for a solution to my own problem, so maybe it can help others looking for the same thing.