2024-10-05 14:26:44 发布
网友
我想画两个相互接触的正方形,但公共边线看起来更粗。 我怎样才能避免呢?(我希望线宽为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)
这是一张照片:
共享段不是较厚,而是较暗。线不能小于1像素。“厚度”为0.1是通过使线条看起来更苍白来实现的
话虽如此,您可以通过不绘制两次来避免公共边的“增厚”:
plt.plot(x1, y, 'k', linewidth = 0.1) plt.plot(x2[:-1], y[:-1], 'k', linewidth = 0.1)
问题出在抗锯齿中
看,我改变了颜色和线宽,所以
plt.plot(x1, y, 'r', linewidth = 5) plt.plot(x2, y, 'g', linewidth = 5)
给予
如您所见,第二个“正方形”的绿线完全覆盖了红色的,而没有增加公共线的宽度
因此,问题不在于matplotlib,而在于以您想要的方式显示如此窄的线,因为它们是抗锯齿的。例如,左上角:
共享段不是较厚,而是较暗。线不能小于1像素。“厚度”为0.1是通过使线条看起来更苍白来实现的
话虽如此,您可以通过不绘制两次来避免公共边的“增厚”:
问题出在抗锯齿中
看,我改变了颜色和线宽,所以
给予
如您所见,第二个“正方形”的绿线完全覆盖了红色的,而没有增加公共线的宽度
因此,问题不在于matplotlib,而在于以您想要的方式显示如此窄的线,因为它们是抗锯齿的。例如,左上角:
相关问题 更多 >
编程相关推荐