使2条重叠的线看起来不更粗

时间:2020-10-23 21:52:57

标签: python matplotlib

我想绘制两个相互接触的正方形,但公共边线显得更粗。 我该如何避免呢? (我希望线宽为0.1,将其更改为另一个值不会解决我的问题)

import matplotlib.pyplot as plt

x1 = [0, 1, 1, 0, 0]
x2 = [0, -1, -1, 0, 0]
y = [0, 0, 1, 1, 0]

plt.plot(x1, y, 'k', linewidth = 0.1)
plt.plot(x2, y, 'k', linewidth = 0.1)

这是一张照片: 2 squares overlapping, making the common line thicker

2 个答案:

答案 0 :(得分:3)

共享段不较粗,而是较暗。一条线不能小于1个像素。通过使线条看起来更浅,可实现0.1的“厚度”。

话虽如此,您可以通过不绘制两次来避免共同边缘的“变厚”:

plt.plot(x1, y, 'k', linewidth = 0.1)
plt.plot(x2[:-1], y[:-1], 'k', linewidth = 0.1)

答案 1 :(得分:1)

问题出在抗锯齿

看,我改变了颜色和线宽,所以

plt.plot(x1, y, 'r', linewidth = 5)
plt.plot(x2, y, 'g', linewidth = 5)

给予

enter image description here

您可能会看到,第二个“正方形”的绿线完全覆盖了红色的,而没有增加公共线的宽度。

所以问题不在matplotlib中,而是以您想要的方式显示如此狭窄的线条,因为它们被抗锯齿-如果放大我的图片,您可能会看到它。例如左上角:

enter image description here

相关问题