在 sympy 绘图中,如何获得具有固定纵横比的绘图? [英] In sympy plotting, how can I get a plot with a fixed aspect ratio?
问题描述
如果我用这个片段绘制一个圆圈
from sympy import *x, y = 符号('x y')p1 = plot_implicit(Eq(x**2 +y**2, 1),aspect_ratio=(1.,1.))
我会得到一个像这样的图形窗口
现在纵横比不是我所期望的,因为我看到的是椭圆而不是圆.此外,如果我改变窗口的纵横比(拖动窗口的右下角)我也会改变情节的纵横比......下图是我的拖动角后得到一个圆:
我想得到一个与您在 Matlab 中设置 axis equal
时得到的图一样的图,请参阅
我错过了什么?
我正在使用 Jupyter 并且笔记本服务器的版本是 4.1.0 并且正在运行:Python 2.7.11 |Anaconda 2.5.0(64 位)|(默认,2015 年 12 月 6 日,18:08:32)[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
现在在 2019 年 9 月此代码有效:
将 matplotlib.pyplot 导入为 plt进口同情x, y = sympy.symbols('x y')plt.ion() #interactive onp1 = sympy.plot_implicit(sympy.Eq(x**2 +y**2, 4), block = False)fg, ax = p1._backend.fig, p1._backend.ax # 获取 matplotib 的图形和坐标轴# 使用 matplotlib 改变外观:ax.axis('tight') # 浮点数或 {'on','off','equal','tight','scaled','normal','auto','image','square'}ax.set_aspect("equal") # 'auto', 'equal' 或正整数是允许的ax.grid(真)plt.ioff() #交互式关闭plt.show()
If I plot a circle with this snippet
from sympy import *
x, y = symbols('x y')
p1 = plot_implicit(Eq(x**2 +y**2, 1),aspect_ratio=(1.,1.))
I will get a figure window like this one
Now the aspect ratio is not what I was expecting because I see an ellipse instead of a circle. Moreover, if I change the aspect ratio of the window (dragging the bottom-right corner of the window) I get also a change in the aspect ratio of the plot... The following image is what I get after dragging the corner in order to see a circle:
I would like to get a plot like the one you get in Matlab when you set axis equal
, see http://it.mathworks.com/help/matlab/creating_plots/aspect-ratio-for-2-d-axes.html when you plot an ellipse
What am I missing?
I am using Jupyter and the version of the notebook server is 4.1.0 and is running on: Python 2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec 6 2015, 18:08:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
now in Sept 2019 this code works:
import matplotlib.pyplot as plt
import sympy
x, y = sympy.symbols('x y')
plt.ion() #interactive on
p1 = sympy.plot_implicit(sympy.Eq(x**2 +y**2, 4), block = False)
fg, ax = p1._backend.fig, p1._backend.ax # get matplotib's figure and axes
# Use matplotlib to change appearance:
ax.axis('tight') # list of float or {‘on’, ‘off’, ‘equal’, ‘tight’, ‘scaled’, ‘normal’, ‘auto’, ‘image’, ‘square’}
ax.set_aspect("equal") # 'auto', 'equal' or a positive integer is allowed
ax.grid(True)
plt.ioff() #interactive off
plt.show()
这篇关于在 sympy 绘图中,如何获得具有固定纵横比的绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!