我刚开始尝试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()
答案 0 :(得分:3)
您使用的是哪个版本的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()