我需要创建一个椭圆图。我的代码如下: -
import numpy as np
import pandas as pd
import math as m
import matplotlib.patches as patches
import matplotlib.pyplot as plt
x1=6.5 #Approach distane measurement point
y1=0.45 #Lateral distance measurement point
Nx=np.linspace(80,60,10)
Ny=np.linspace(80,60,10)
c=20
a=(10**(Nx/c))
b=(10**(86/20))
x=x1*(a/b) #semi major axis
Final_calculation=pd.DataFrame(x,columns = ["Distance_xaxis"])
a=(10**(Ny/c))
b=(10**(83/20))
y=y1*(a/b) #semi mionr axis
Final_calculation['Distance_yaxis']=y
Final_calculation['Sound unit decibel']=Nx
fig = plt.figure()
ax = fig.add_subplot(111, aspect='auto')
e1 = patches.Ellipse((0,0),x[0],y[0],linewidth=2, fill=False, zorder=2)
ax.add_patch(e1)
答案 0 :(得分:3)
您可以使用ax.autoscale
打开两个轴的自动缩放(而不是手动增加轴限制):
ax.autoscale(True)
您的代码变为
x1=6.5 #Approach distane measurement point
y1=0.45 #Lateral distance measurement point
Nx=np.linspace(80,60,10)
Ny=np.linspace(80,60,10)
c=20
a=(10**(Nx/c))
b=(10**(86/20))
x=x1*(a/b) #semi major axis
Final_calculation=pd.DataFrame(x,columns = ["Distance_xaxis"])
a=(10**(Ny/c))
b=(10**(83/20))
y=y1*(a/b) #semi mionr axis
Final_calculation['Distance_yaxis']=y
Final_calculation['Sound unit decibel']=Nx
fig = plt.figure()
ax = fig.add_subplot(111, aspect='auto')
e1 = patches.Ellipse((0,0),x[0],y[0],linewidth=2, fill=False, zorder=2)
ax.add_patch(e1)
ax.autoscale(True)
plt.show()