使用matplotlib.patches.Arc
可以使半椭圆形,只需指定关键字theta1=0.0, theta2=180.0
(或90至270)。 我写了一个名为arcs
的包装函数,用于制作Arc
s的散点图。 它使用PatchCollection,应该有更好的性能并启用colorbar。 你可以在gist (link)找到它。
下面是一个例子:
a = np.arange(11)
arcs(a, a, w=4, h=a, rot=a*30, theta1=0.0, theta2=180.0,
c=a, alpha=0.5, edgecolor='none')
plt.colorbar()
的简要实施arcs
张贴下面完整性埃德·史密斯建议。
def arcs(x, y, w, h, rot=0.0, theta1=0.0, theta2=360.0,
c='b', **kwargs):
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Arc
from matplotlib.collections import PatchCollection
if np.isscalar(c):
kwargs.setdefault('color', c)
c = None
zipped = np.broadcast(x, y, w, h, rot, theta1, theta2)
patches = [Arc((x_, y_), w_, h_, rot_, t1_, t2_)
for x_, y_, w_, h_, rot_, t1_, t2_ in zipped]
collection = PatchCollection(patches, **kwargs)
if c is not None:
c = np.broadcast_to(c, zipped.shape).ravel()
collection.set_array(c)
ax = plt.gca()
ax.add_collection(collection)
return collection
完整版可以在gist (link)找到。
仅供参考,'matplotlib.patches.Arc'可以填充半椭圆。 –
你有这个@Syrtis Major的参考吗?这里是'matplotlib.patches.Arc'官方文档:http://matplotlib.org/api/patches_api.html#module-matplotlib.patches明确地说:“因为它执行各种优化,所以不能填充。” –
啊,我没有注意到文档,但只是试了一下(见下面的答案)。我不确定为什么,也许文档有点过时? –