4

我刚刚开始尝试使用 matplotlib,因为我经常遇到需要绘制一些数据的情况,matplotlib 似乎是一个很好的工具。我试图在主站点中调整椭圆示例,以便改为绘制两个圆圈,但是在运行代码之后,我发现没有显示任何补丁,我无法弄清楚到底是什么问题.. . 这是代码。提前致谢。

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.patches as mpatches

plt.axis([-3,3,-3,3])
ax = plt.axes([-3,3,-3,3])
# add a circle
art = mpatches.Circle([0,0], radius = 1, color = 'r', axes = ax)

ax.add_artist(art)

#add another circle
art = mpatches.Circle([0,0], radius = 0.1, color = 'b', axes = ax)

ax.add_artist(art)

print ax.patches

plt.show()
4

1 回答 1

6

您使用的是哪个版本的 matplotlib?我无法复制您的结果,我可以很好地看到两个省略号。我的目标很远,但我想你的意思是做这样的事情:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import matplotlib.patches as mpatches

# create the figure and the axis in one shot
fig, ax = plt.subplots(1,figsize=(6,6))

art = mpatches.Circle([0,0], radius = 1, color = 'r')
#use add_patch instead, it's more clear what you are doing
ax.add_patch(art)

art = mpatches.Circle([0,0], radius = 0.1, color = 'b')
ax.add_patch(art)

print ax.patches

#set the limit of the axes to -3,3 both on x and y
ax.set_xlim(-3,3)
ax.set_ylim(-3,3)

plt.show()
于 2012-12-10T11:49:20.703 回答