小编waq*_*aqy的帖子

matplotlib路径线宽连接到图缩放

是否可以将matplotlib路径的线宽与图形缩放/比例级别联系起来?

我正在绘制一张地图,其中matplotlib路径(带有贝塞尔曲线)在地图上绘制道路.在放大时,我希望放大路径的宽度.

在附加脚本中,多边形近似可以正确缩放,但路径(红线)不能缩放(宽度).

是否可以将线宽与某种比例转换联系起来并通过回调重绘?

import matplotlib.pyplot as plt
from matplotlib.path import Path
import matplotlib.patches as patches
import numpy as np

def main():
  ax = plt.subplot(111)
  verts = np.array([ (0., 0.), (0.5, .5), (1., 0.8), (0.8, 0.)])
  codes = np.array([Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.LINETO ])

  # Can this curve have zoomable width
  path = Path(verts, codes)
  patch = patches.PathPatch(path, fc='none', color='r', lw=4, zorder=3)
  ax.add_patch(patch)

  ax.plot(verts[:,0], verts[:,1], 'o--', lw=2, color='k', zorder=2)

  # these will be polygonal approx that will have proper zoom
  v=np.array([]).reshape((-1,2)) …
Run Code Online (Sandbox Code Playgroud)

python matplotlib python-3.x

3
推荐指数
1
解决办法
1213
查看次数

标签 统计

matplotlib ×1

python ×1

python-3.x ×1