【问题标题】:Boundaries of rectangles / plots in matplotlibmatplotlib 中矩形/绘图的边界
【发布时间】:2014-12-20 23:17:55
【问题描述】:

我正在尝试使用 matplotlib 中的 patch.rectangle 创建一组图形,但似乎矩形边界中的模糊会导致一些重叠。例如,如果我使用这两个绿色矩形:

http://puu.sh/cpzFw/fe6ed8834d.png

(我没有代表直接插入图片)

我不确定如何删除边界。此外,我如何将它也适应子图坐标,因为情节也是如此。

谢谢!

编辑: 抱歉,这里有一些示例代码:

  for i in range(nrows):
    for (count, num) in enumerate(listx[2 * i + 1]):
      if count == 0:
          rect_start = count
      elif num == listx[2 * i + 1][count-1]:
          length += 1
      elif listx[2 * i + 1][count] != listx[2 * i + 1][count-1]:
          if listx[2 * i + 1][count-1] == '0':
              r1 = ptch.Rectangle((rect_start,i), length, 1, color="blue", fill=True)
              rect.add_patch(r1)
              length = 1
              rect_start = count    
          if listx[2 * i + 1][count-1] == '1':
              r1 = ptch.Rectangle((rect_start,i), length, 1, color="black", fill=True)
              rect.add_patch(r1)
              length = 1
              rect_start = count
          if listx[2 * i + 1][count-1] == '2':
              r1 = ptch.Rectangle((rect_start,i), length, 1, color="red", fill=True)
              rect.add_patch(r1)
              length = 1
              rect_start = count
          if listx[2 * i + 1][count-1] == '3':
              r1 = ptch.Rectangle((rect_start,i), length, 1, color="green", fill=True)
              rect.add_patch(r1)
              length = 1
              rect_start = count
          if not listx[2 * i + 1][count-1].isdigit():
              r1 = ptch.Rectangle((rect_start,i), length, 1, color="yellow", fill=True)
              rect.add_patch(r1)
              length = 1
              rect_start = count

【问题讨论】:

  • 请提供最小的示例代码来重现您的图像。

标签: python-2.7 matplotlib matplotlib-basemap


【解决方案1】:

我很幸运设置ec='none'。边缘是用一条线(以点为单位的粗细)绘制的,因此会导致一些不精确的重叠。
顺便说一句:如果你想要精确的尺寸和类似边缘的效果,你总是可以在不同颜色的矩形顶部放置一个稍微小一点的彩色矩形(都带有ec='none')。

【讨论】:

    猜你喜欢
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 2015-02-13
    • 2013-10-03
    相关资源
    最近更新 更多