From 938f2fcc5a8fcbb1115d087d551eebe9f3ba481d Mon Sep 17 00:00:00 2001 From: geekincode Date: Mon, 1 Nov 2021 22:45:11 +0800 Subject: [PATCH] Update Hyperbola_draw.py --- Hyperbola_draw.py | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Hyperbola_draw.py b/Hyperbola_draw.py index 9a777d4..eb13e88 100644 --- a/Hyperbola_draw.py +++ b/Hyperbola_draw.py @@ -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() -- GitLab