pythonplotting,Sympy and plotting

问题

I have a few questions about what how to work with graphics, using Sympy.

My code:

from sympy import *

x, y = symbols("x y")

plot_implicit(Eq(x**2 + y**2, 4), (x, -3, 3), (y, -3, 3))

1) The graph is obtained stretched along the x axis.

How to make so that the curve looked like a circle?

2) How to add other elements to the chart. For example, the point O(0, 0) and the line y = x.

回答1:

According to the docstring of plot.py, you can get the backend wrapper of the Matplotlib axes and figure that SymPy uses, through _backend attribute, and then modify properties as any other Matplotlib objects. Check this example:

import matplotlib.pyplot as plt

import numpy as np

%matplotlib notebook

from sympy import *

x, y = symbols("x y")

hp = plot_implicit(Eq(x**2 + y**2, 4), (x, -3, 3), (y, -3, 3))

fig = hp._backend.fig

ax = hp._backend.ax

xx = yy = np.linspace(-3,3)

ax.plot(xx,yy) # y = x

ax.plot([0],[0],'o') # Point (0,0)

ax.set_aspect('equal','datalim')

fig.canvas.draw()

The Sympy Plot objects have append and extend methods that allows add a Plot object to other, but this don't work (at least for me and using Jupyter).

Another option is use only Matplotlib:

import matplotlib.pyplot as plt

import numpy as np

fig, ax = plt.subplots(1,1)

xx,yy = np.linspace(-3,3), np.linspace(-3,3)

x,y = np.meshgrid(xx,yy)

ax.contour(x, y, (x**2+y**2-4), [0]);

ax.plot([0],[0],"o")

ax.plot(xx,yy)

ax.set_aspect('equal','datalim')

来源:https://stackoverflow.com/questions/40747474/sympy-and-plotting

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值