提交 938f2fcc 编写于 作者: geekincode's avatar geekincode 💬

Update Hyperbola_draw.py

上级 13547ac4
......@@ -35,17 +35,18 @@ class hyperbola():
y.sort(reverse=True)
x2 = list(np.linspace(a,line_range,line_range*10))
x2 = x2[::-1] + x2
return x1,y,x2
self.data = x1,y,x2
def hb_draw(self,data):
ax = self.ax
def hb_draw(self,line_color='lightcoral'):
ax,data = self.ax, self.data
if self.focus == 'x':
ax.plot(data[0], data[1], color='lightcoral', label='hyperbola')
ax.plot(data[2], data[1], color='lightcoral')
ax.plot(data[0], data[1], color=line_color, label='hyperbola')
ax.plot(data[2], data[1], color=line_color)
elif self.focus == 'y':
ax.plot(data[1], data[0], color='lightcoral', label='hyperbola')
ax.plot(data[1], data[2], color='lightcoral')
ax.plot(data[1], data[0], color=line_color, label='hyperbola')
ax.plot(data[1], data[2], color=line_color)
else:
print('You maked an error on focus!!!')
......@@ -67,18 +68,18 @@ class hyperbola():
ax.legend()
def asymptote(self):
def asymptote(self,ax_color='skyblue'):
import numpy as np
line_range, focus = self.line_range, self.focus
line_range = self.line_range
x = list(np.linspace(-line_range,line_range,10)) #渐近线
y = [(self.b/self.a)*x_ for x_ in x]
if self.focus == 'x':
self.ax.plot(x, y, color='skyblue')
self.ax.plot(x[::-1], y, color='skyblue')
self.ax.plot(x, y, color=ax_color)
self.ax.plot(x[::-1], y, color=ax_color)
elif self.focus == 'y':
self.ax.plot(y, x, color='skyblue')
self.ax.plot(y, x[::-1], color='skyblue')
self.ax.plot(y, x, color=ax_color)
self.ax.plot(y, x[::-1], color=ax_color)
def display(self):
self.plt.show()
......@@ -86,12 +87,12 @@ class hyperbola():
if __name__ == '__main__':
h = hyperbola(30,100)
d1 = h.hb_data(10,13,focus='x')
h.hb_draw(d1)
h.asymptote()
d2 = h.hb_data(10,13,focus='y')
h.hb_draw(d2)
h.asymptote()
h.hb_data(10,13,focus='x')
h.hb_draw('black')
h.asymptote('#FF1499')
h.hb_data(10,13,focus='y')
h.hb_draw('black')
h.asymptote('red')
h.display()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册