python - 如何自动缩放绘图画布
问题描述
我有大小为 10x10 的情节
y, x = np.mgrid[-10:10:100j, -10:10:100j]
当我画小图形时 - 一切都很好。但是当坐标超出图表时,我会看到问题。如何自动缩放绘图画布?
def f(x,a,b):
return x**3+a*x + b
def show_plot(plt, A,B,P,Q): #A=-7, B=10, P=4, Q=8
y, x = np.mgrid[-10:10:100j, -10:10:100j]
xp = P
yp = np.sqrt(f(xp,A,B))
xq = Q
yq = np.sqrt(f(xq,A,B))
m = 0.0
if P==Q:
xx = 3*pow(xp,2)
m = (xx+A)/(2*yp)
pass
else:
m=(yp-yq)/(xp-xq) #m
xr = m*m-xp-xq
yr1 = yp+m*(xr-xp)
yr2 = yq+m*(xr-xq)
plt.contour(x, y, y**2 - f(x,A,B), levels=[0])
b = -xp*m + yp
poly = np.poly1d([-1, m**2, 2*m*b+3, b**2-5])
x = np.roots(poly)
y = np.sqrt(f(x,A,B))
x = np.linspace(-5, 5)
plt.plot(x, m*x+b)
coordinates = [('P',xp,yp), ('Q',xq,yq), ('-R',xr,-yr1)]
for x in coordinates:
plt.plot(x[1], x[2], 'ro-')
plt.annotate(x[0], xy=(x[1]-0.2, x[2]+0.2), horizontalalignment='right', verticalalignment='top',family='fantasy')
plt.plot([xr,xr],[yr1,-yr1],'g-')
plt.grid(True)
解决方案
推荐阅读
- azure-devops - Azure DevOps Pipeline 的另一个说明:-d--- 和 -a--- 模式
- asp.net - 程序集使用 'System.Runtime' 版本 = 4.2.2.0,它的版本高于引用的程序集 'System.Runtime' 版本 = 4.1.2.0
- azure - 错误 CS0122:“TimelineEditor.window”由于其保护级别而无法访问
- java - 如何在 Java 中将多个网格从文本文件读取到二维数组?
- r - R中线性回归的MH算法的实现
- r - 能否获得 R 的 TidyModel 框架中随机森林模型的袋外误差?
- python - 在python中查找局域网上另一台计算机的IP地址
- http - PlayFramework 在长时间运行的请求中导致 502 Bad gateway
- makefile - jamfile:将文件复制到不同的目录
- sql - How to Join Conditionally to Different Tables