Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matplotlib Pyplot:在屏幕上安装一个补丁(圆)_Matplotlib - Fatal编程技术网

Matplotlib Pyplot:在屏幕上安装一个补丁(圆)

Matplotlib Pyplot:在屏幕上安装一个补丁(圆),matplotlib,Matplotlib,我用下面的代码画了一个圆。我设置了Pyplot,使图形占据整个屏幕。当它是一个较小的屏幕,它会出现一个圆圈,但全屏使它扭曲。如何使圆形图保持1:1的比例?(也就是说,我希望保持圆圈居中且外观相同,黑色背景填充屏幕的其余部分。) 谢谢 #Necessary imports import matplotlib as plt plt.use('TkAgg') import matplotlib.pyplot as plt #Initialize/define stuff circle = plt.C

我用下面的代码画了一个圆。我设置了Pyplot,使图形占据整个屏幕。当它是一个较小的屏幕,它会出现一个圆圈,但全屏使它扭曲。如何使圆形图保持1:1的比例?(也就是说,我希望保持圆圈居中且外观相同,黑色背景填充屏幕的其余部分。)

谢谢

#Necessary imports
import matplotlib as plt
plt.use('TkAgg')
import matplotlib.pyplot as plt

#Initialize/define stuff
circle = plt.Circle((0.5, 0.5), 0.2, color='white')
fig, ax = plt.subplots() # note we must use plt.subplots, not plt.subplot
plt.axis('off')
figManager = plt.get_current_fig_manager()
figManager.full_screen_toggle()

#Display
ax.add_artist(circle)
fig.set_facecolor("black")
plt.show()

您可以为x轴和y轴指定相等的纵横比,因为默认情况下,x轴和y轴具有相等的限制。具体来说,你可以这样做

ax.add_artist(circle)
ax.set_aspect('equal') # <----------- Added here
fig.set_facecolor("black")
ax.添加艺术家(圆圈)

ax.set_aspect('equal')#@IoBE:恕我直言,我很欣赏在StackOverflow上节俭的实用性,但我认为这个问题是独特的,因为:(a)它是以不同的方式提出的(另一个问题有很多行话,我不能马上理解);(b) 从Bazingaa获得的解决方案要简单得多。