Matplotlib线宽基于轴,而不是点 [英] Matplotlib line width based on axis, not on points

查看:162
本文介绍了Matplotlib线宽基于轴,而不是点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在Matplotlib中设置线宽,则必须以点为单位给出线宽.就我而言,我有两个半径均为R的圆,我想用一条线将它们连接起来.我希望这条线的宽度为2 * R,以便获得杆状形状.但是当我说myLines[i].set_linewidth(2*R)时,无论我放大了多少,线都始终具有特定的粗细.

If you set a line width in Matplotlib, you have to give the line width in points. In my case, I have two circles, both with radius R and I want to connect them with a line. I want this line to be 2*R wide in order to get a rod-shape. But when I say myLines[i].set_linewidth(2*R) this makes the lines always a specific thickness, regardless of how much I have zoomed in.

有没有一种方法可以使线条具有特定的粗细,而不取决于像素或点的数量,而是根据轴进行缩放?如何使线的宽度与圆的直径相同?

Is there a way to make lines a specific thickness not based on the number of pixels or points, but scaling with the axis? How can I make my line have the same width as the diameter of my circles?

我希望我对自己的解释足够好,期待得到答案.

I hope I explained myself well enough and I am looking forward to an answer.

推荐答案

以数据为单位的行

为了用数据单位的线宽画一条线,您可能想看看 此答案 .

Line in Data units

In order to draw a line with the linewidth in data units, you may want to have a look at this answer.

它使用类data_linewidth_plot,该类非常类似于plt.plot()命令的签名.

It uses a class data_linewidth_plot which closely resembles the plt.plot() command's signature.

l = data_linewidth_plot( x, y, ax=ax, label='some line', linewidth = 1, alpha = 0.4)

linewidth参数以(y-)数据单位解释.

The linewidth argument is interpreted in (y-)data units.

使用这种解决方案,甚至不需要画圆,因为人们可以简单地使用solid_capstyle="round"自变量.

Using this solution there is not even any need for drawing circles, since one may simply use the solid_capstyle="round" argument.

R=0.5
l = data_linewidth_plot( [0,3], [0.7,1.4], ax=ax, solid_capstyle="round", 
                        linewidth = 2*R, alpha = 0.4)

使用矩形和两个圆更容易制造杆.

A rod is much more easily produced using a rectange and two circles.

这篇关于Matplotlib线宽基于轴,而不是点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆