【发布时间】:2016-03-12 14:01:30
【问题描述】:
【问题讨论】:
-
jpg图片的链接不存在了
标签: python matplotlib patch
【问题讨论】:
标签: python matplotlib patch
要创建任意形状,您需要使用 matplotlib.patches.Polygon 类并提供足够的 x,y 样本以使其看起来像必要的平滑路径(在一天结束时它仍然是直线段当你放大到足够近时)。
如果您只有几个点,您可以使用多个interpolation methods 之一(例如scipy.interpolate.spline)来创建数据的平滑插值,然后您可以将其提供给Polygon 构造函数。
这是一个使用Polygon 类通过在圆周围提供x,y 点来创建圆的简单示例。
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
# Circle coordinates (100 points around the circle)
t = np.linspace(0, 2 * np.pi, 100).reshape(100,1)
coords = np.concatenate((np.cos(t), np.sin(t)), axis=1)
ax = plt.axes()
polygons = [];
polygons.append(Polygon(coords))
p = PatchCollection(polygons, alpha=0.4)
ax.add_collection(p)
ax.axis('equal')
【讨论】:
听起来就像官方文档中的例子:
http://matplotlib.org/examples/pylab_examples/ellipse_demo.html
主要部分,他们只是构造一个椭圆列表:
ells = [Ellipse(xy=rnd.rand(2)*10, width=rnd.rand(), height=rnd.rand(), angle=rnd.rand()*360) for i in range(250)]
...还是我错过了你的意思? :)
【讨论】: