1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python画椭圆形_如何绘制Python中的半椭圆?

python画椭圆形_如何绘制Python中的半椭圆?

时间:2021-07-15 18:48:42

相关推荐

python画椭圆形_如何绘制Python中的半椭圆?

使用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)找到。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。