使用matplotlib在屏幕上绘制线条和圆圈

时间:2012-09-12 12:40:16

标签: python matplotlib

我想使用matplotlib在屏幕上绘制一些线条和圆圈。我不需要X轴和Y轴。这可能吗?我该怎么办?

2 个答案:

答案 0 :(得分:1)

您可以使用axes.get_xaxis().set_visible(False)或使用axis('off')隐藏轴。

示例:

from pylab import *

gca().get_xaxis().set_visible(False) # Removes x-axis from current figure
gca().get_yaxis().set_visible(False) # Removes y-axis from current figure

a = arange(10) 
b = sin(a)
plot(a, b)
show() # Plot has no x and y axes

答案 1 :(得分:1)

如果您不想要轴,并且乐意在0-1范围内工作:

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

fig = plt.figure()
fig.patches.append(mpatches.Circle([0.5, 0.5], 0.25, transform=fig.transFigure))
fig.show()

使用@Dhara的解决方案有几个好处。主要是您可以使用自动扩展到数据的数据坐标系,但如果您只想绘制几个形状,我的解决方案效果很好。

如果沿着我所解释的路线前进,可以使用一些有用的文档: