【发布时间】:2021-04-20 15:10:57
【问题描述】:
如何去除内圆内和外圆外的线段?我编写了以下 python 代码来绘制两个带有 x=0 线的圆圈:
import matplotlib.pyplot as plt
plt.figure(figsize=(10,10))
plt.rcParams.update({'font.size': 14})
#Plot circle
#Create a list of 500 points with equal spacing between -1 and 1
import numpy as np
x=np.linspace(start=-1,stop=1,num=500)
#Find y1 and y2 for these points
y_positive=lambda x: np.sqrt(1-x**2)
y_negative=lambda x: -np.sqrt(1-x**2)
plt.plot(x,list(map(y_positive, x)), color='maroon')
plt.plot(x,list(map(y_negative, x)),color='maroon')
#Plot smaller circle
x=np.linspace(start=-0.5,stop=0.5,num=500)
y_positive=lambda x: np.sqrt(0.5**2-x**2)
y_negative=lambda x: -np.sqrt(0.5**2-x**2)
plt.plot(x,list(map(y_positive, x)), color='maroon')
plt.plot(x,list(map(y_negative, x)),color='maroon')
#Create broken lines
#x=np.linspace(start=-1,stop=1,num=30)
plt.axvline(0,-1,1,color='maroon')
plt.savefig('circle[enter image description here][1].pdf')
谢谢。
【问题讨论】:
标签: python numpy matplotlib subplot