日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

学习Python中用numpy与matplotlib遇到的一些数学函数与函数的绘图

發(fā)布時間:2023/12/10 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 学习Python中用numpy与matplotlib遇到的一些数学函数与函数的绘图 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

學習Python中的一些數(shù)學函數(shù)與函數(shù)的繪圖

主要用到numpy 與 matplotlib
如果有什么不正確,歡迎指教。

圖片不知道怎樣批量上傳,一個一個怎么感覺很小,請見諒

自行復制拷貝,到vs,jupyter notebook, spyder都可以

函數(shù) y=x?sinxy = x - sinx y=x?sinx

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題x1 = np.linspace(-np.pi, np.pi, 1000) y1 = x1 - np.sin(x1)plt.plot(x1, y1, c = 'k', label = r"$ y=x-sinx $")plt.grid() plt.legend() plt.show()

函數(shù) y=3x4?4x3+1y = 3x^4 - 4x^3 + 1 y=3x4?4x3+1

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題x1 = np.linspace(-1, 1.5, 1000) y1 = 3 * (x1 ** 4) - 4 * (x1 ** 3) + 1 plt.plot(x1, y1, label = r"$ y = 3x^4 - 4x^3 + 1 $")plt.grid() plt.legend() plt.show()

函數(shù) y=x4y = x^4 y=x4

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題x1 = np.linspace(-5, 5, 1000) y1 = x1 ** 4plt.plot(x1, y1, label = r"$ y = x^4 $")plt.grid() plt.legend() plt.show()

函數(shù) y=x3y = \sqrt[3]{x} y=3x?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題x1 = np.linspace(0, 5, 1000) y1 = x1 ** (1/3)plt.plot(x1, y1, label = r"$ y = \sqrt[3]{x} $")# plt.xlim([-np.pi, np.pi]) # plt.ylim([-1.5, 1.5]) plt.grid() plt.legend() plt.show()

函數(shù) y=2x3?9x2+12x?3y=2x^3-9x^2+12x-3 y=2x3?9x2+12x?3

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題x1 = np.linspace(-2, 5, 1000) y1 =2 * (x1 ** 3) - 9 * (x1 ** 2) + 12 * x1 - 3plt.plot(x1, y1, label = r"$ y=2x^3-9x^2+12x-3 $")plt.grid() plt.legend() plt.show()

函數(shù) y=2x3?6x2?18x+7y=2x^3-6x^2-18x+7 y=2x3?6x2?18x+7

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題x1 = np.linspace(-3, 5, 1000) y1 = 2 * (x1 ** 3) - 6 * (x1 ** 2) - 18 * x1 + 7plt.plot(x1, y1, label = r"$ y=2x^3-6x^2-18x+7 $")# plt.axis('equal') plt.grid() plt.legend() plt.show()

三次拋物線 y=x3y = x^3 y=x3

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0))x1 = np.linspace(-5, 5, 1000) y1 = x1 ** 3plt.plot(x1, y1, label = r"$ y = x^3 $")plt.grid() plt.legend() plt.show()

半立方拋物線 y2=ax3y^2 = ax^3 y2=ax3

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題a = 0.1 t = np.linspace(-5, 5, 1000) x = t ** 2 y = a * (t ** 3) plt.plot(x, y, label = r"y^2 = ax^3|a=0.1")a = 1 y1 = a * (t ** 3) plt.plot(x, y1, label = r"y^2 = ax^3|a=1")# plt.xlim([-np.pi, np.pi]) # plt.ylim([-1.5, 1.5]) plt.grid() plt.legend() plt.show()

概率曲線 y=e?x2y=e^{-x^2} y=e?x2

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題t = np.linspace(-2, 2, 1000) x = t y = np.e ** -(x ** 2) plt.plot(x, y, label = r"$ y=e^{-x^2} $")plt.axis('equal') # plt.grid() plt.legend() plt.show()

箕舌線 y=8a3x2+4a2y =\frac{8a^3}{x^2+4a^2} y=x2+4a28a3?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題a = 1 t = np.linspace(-5, 5, 1000) x = t y = (8 * a ** 2) / (x ** 2 + 4 * a ** 2) plt.plot(x, y, label = r"$ y =\frac{8a^3}{x^2+4a^2} |_{a=1} $")a = 2 y1 = (8 * a ** 2) / (x ** 2 + 4 * a ** 2) plt.plot(x, y1, label = r"$ y =\frac{8a^3}{x^2+4a^2} |_{a=2} $")plt.axis('equal') # plt.grid() plt.legend() plt.show()

蔓葉線 y2(2a?x)=x3y^2(2a-x)=x^3 y2(2a?x)=x3x=2asin2θ,y=2a2tan2θsin4θx=2asin^2\theta, y=2a^2tan^2\theta sin^4\theta x=2asin2θ,y=2a2tan2θsin4θ

修改:之前x的取值是?3.6≤x≤3.6-3.6\leq x \leq3.6?3.6x3.6, 實際上x的值是 ≥0\geq 00

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題a = 2 #這是原來的取值范圍 #t = np.linspace(-3.6, 3.6, 1000) #x = np.abs(t) #這是現(xiàn)在的取值范圍 t = np.linspace(0, 3.6, 1000) x = t #還有我用power替代了sqrt開根號 y = np.power((x ** 3) / (2 * a - x), 1/2) plt.plot(x, y, 'b', x, -y, 'b', label = r"$ y^2(2a-x)=x^3 $")plt.grid() plt.legend() plt.show()

ρ=2a?tan2θ\rho=2a-tan^2\theta ρ=2a?tan2θ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) plt.ylim([0, 6])a = 1 theta = np.arange(0, 2 * np.pi, np.pi / 100) rho = 2 * a - np.tan(theta) ** 2 plt.plot(theta, rho, label = r'$\rho=2a-tan^2\theta \quad |a=1$')a = 1.5 r2 = a * rho plt.plot(theta, r2, label = r'$\rho=2a-tan^2\theta \quad |a=1.5$')a = 2.5 r2 = a * rho plt.plot(theta, r2, label = r'$\rho=2a-tan^2\theta \quad |a=2.5$')plt.legend() plt.show()

笛卡兒葉形線畫圖 極坐標 r=3asinθcosθsin3θ+cos3θr = \frac{3asin\theta cos\theta}{sin^3\theta + cos^3\theta} r=sin3θ+cos3θ3asinθcosθ?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) plt.ylim([0, 6])a = 1 theta = np.arange(0, 2 * np.pi, np.pi / 100) r = 3 * a * np.sin(theta) * np.cos(theta) / (np.sin(theta) ** 3 + np.cos(theta) ** 3) plt.plot(theta, r, label = r'$ r = \frac{3asin\theta cos\theta}{sin^3\theta + cos^3\theta} $')a = 1.5 r2 = a * r plt.plot(theta, r2)a = 2.5 r2 = a * r plt.plot(theta, r2)# plt.grid() plt.legend() plt.show()

笛卡兒葉形線 直角坐標 x3+y3?3axy=0x^3+y^3-3axy=0 x3+y3?3axy=0x=3at1+t3,y=3at21+t3x=\frac{3at}{1+t^3}, y=\frac{3at^2}{1+t^3} x=1+t33at?,y=1+t33at2?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 # plt.subplot(111, polar = True) # plt.ylim([0, 6])a = 1 # t = np.arange(-0.1, 4 * np.pi, np.pi / 180) t = np.linspace(-0.5, 200, 5000) x = (3 * a * t) / (1 + t ** 3) y = (3 * a * t ** 2) / (1 + t ** 3) plt.plot(x, y, label = r'$ x=\frac{3at}{1+t^3}, y=\frac{3at^2}{1+t^3} $')a = 1.5 x1 = (3 * a * t) / (1 + t ** 3) y1 = (3 * a * t ** 2) / (1 + t ** 3) plt.plot(x1, y1, label = r'$ x=\frac{3at}{1+t^3}, y=\frac{3at^2}{1+t^3} $')# plt.grid() plt.legend() plt.show()

星形線(內(nèi)擺線的一種) x23+y23=a23x^\frac{2}{3}+y^\frac{2}{3}=a^\frac{2}{3} x32?+y32?=a32?{x=acos3θy=asin3θ\begin{cases} x=acos^3\theta \\ y=asin^3\theta \end{cases} {x=acos3θy=asin3θ?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題a = 1 theta = np.arange(0, 2 * np.pi, np.pi / 180) x = a * np.cos(theta) ** 3 y = a * np.sin(theta) ** 3 plt.plot(x, y, label = r'$ x=acos^3\theta, y=asin^3\theta \quad|a=1$')a = 2 x1 = a * x y1 = a * y plt.plot(x1, y1, label = r'$ x=acos^3\theta, y=asin^3\theta \quad|a=2$')a = 3 x2 = a * x y2 = a * y plt.plot(x2, y2, label = r'$ x=acos^3\theta, y=asin^3\theta \quad|a=3$')ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0))plt.axis('equal') plt.legend() plt.show()

擺線 {x=a(θ?sinθ)y=a(1?cosθ)\begin{cases} x=a(\theta-sin\theta) \\ y=a(1-cos\theta) \end{cases} {x=a(θ?sinθ)y=a(1?cosθ)?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 # plt.subplot(111, polar = True) # plt.ylim([0, 6])a = 1 theta = np.arange(0, 4 * np.pi, np.pi / 180) x = a * (theta - np.sin(theta)) y = a * (1 - np.cos(theta)) plt.plot(x, y, label = r'$ x=a(\theta-sin\theta),\quad y=a(1-cos\theta) \quad|a=1$')a = 2 x1 = a * x y1 = a * y plt.plot(x1, y1, label = r'$ x=a(\theta-sin\theta),\quad y=a(1-cos\theta) \quad|a=2$')a = 3 x2 = a * x y2 = a * y plt.plot(x2, y2, label = r'$ x=a(\theta-sin\theta),\quad y=a(1-cos\theta) \quad|a=3$')ax = plt.gca() ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data', 0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data', 0))plt.axis('equal') plt.legend() plt.show()

心形線(外擺線的一種) KaTeX parse error: Can't use function '$' in math mode at position 27: …a\sqrt{x^2+y^2}$? 或 $ \rho=a(1-c…

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) # plt.ylim([0, 6])a = 1 theta = np.arange(0, 2 * np.pi, np.pi / 180) y = a * (1 - np.cos(theta)) plt.plot(theta, y, label = r'$ \rho=a(1-cos\theta) $')y1 = a * (1 - np.sin(theta)) plt.plot(theta, y1, label = r'$ \rho=a(1-sin\theta) $')# a = 2 # x1 = a * x # y1 = a * y # plt.plot(x1, y1, label = r'$ x=a(\theta-sin\theta),\quad y=a(1-cos\theta) \quad|a=2$')# a = 3 # x2 = a * x # y2 = a * y # plt.plot(x2, y2, label = r'$ x=a(\theta-sin\theta),\quad y=a(1-cos\theta) \quad|a=3$')# ax = plt.gca() # ax.spines['right'].set_color('none') # ax.spines['top'].set_color('none') # ax.xaxis.set_ticks_position('bottom') # ax.spines['bottom'].set_position(('data', 0)) # ax.yaxis.set_ticks_position('left') # ax.spines['left'].set_position(('data', 0))# plt.axis('equal') plt.legend() plt.show()

x=sinθ,y=cosθ+x23x=sin\theta,\quad y=cos\theta+\sqrt[3]{x^2}x=sinθ,y=cosθ+3x2?

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題a = 1 theta = np.arange(0, 2 * np.pi, np.pi / 180) x = np.sin(theta) y = np.cos(theta) + np.power((x ** 2), 1 / 3) #原來用 y = np.cos(theta) + np.power(x, 2/3)只畫出一半,而且報power的錯 plt.plot(x, y, label = r'$x=sin\theta,\quady=cos\theta+\sqrt[3]{x^2}$')# ax = plt.gca() # ax.spines['right'].set_color('none') # ax.spines['top'].set_color('none') # ax.xaxis.set_ticks_position('bottom') # ax.spines['bottom'].set_position(('data', 0)) # ax.yaxis.set_ticks_position('left') # ax.spines['left'].set_position(('data', 0))plt.axis('equal') #等比例會好看點 plt.legend() plt.show()

阿基米德螺線 ρ=aθ\rho=a\thetaρ=aθ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) # plt.ylim([0, 6])a = 1 theta = np.arange(0, 4 * np.pi, np.pi / 180) rho = a * theta plt.plot(theta, rho, label = r'$\rho=a\theta$', linestyle = 'solid')# rho1 = - a * theta # plt.plot(theta, rho1, label = r'$\rho=a\theta$')plt.legend() plt.show()

對數(shù)螺線 ρ=eaθ\rho=e^{a\theta} ρ=eaθ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) plt.ylim([0, 10])a = 0.1 theta = np.arange(0, 6 * np.pi, np.pi / 180) rho = np.e ** (a * theta) plt.plot(theta, rho, label = r'$ \rho=e^{a\theta} $', linestyle = 'solid')a = 0.2 rho1 = np.e ** (a * theta) plt.plot(theta, rho1, label = r'$ \rho=e^{a\theta} $', linestyle = 'solid')plt.legend() plt.show()

雙曲螺旋線 ρθ=a\rho\theta=a ρθ=a

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) plt.ylim([0, 30])a = 30 theta = np.arange(0.01, 6 * np.pi, np.pi / 180) rho = a / theta plt.plot(theta, rho, label = r'$ \rho\theta=a \quad |a=30 $', linestyle = 'solid')a = 50 rho1 = a / theta plt.plot(theta, rho1, label = r'$ \rho\theta=a \quad |a=50 $', linestyle = 'solid')plt.legend() plt.show()

伯努利雙紐線 (x2+y2)2=2a2xy(x^2+y^2)^2=2a^2xy(x2+y2)2=2a2xy(x2+y2)2=a2(x2?y2)(x^2+y^2)^2=a^2(x^2-y^2)(x2+y2)2=a2(x2?y2)ρ2=a2sin2θ\rho^2=a^2sin2\theta ρ2=a2sin2θρ2=a2cos2θ\rho^2=a^2cos2\thetaρ2=a2cos2θ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 # plt.subplot(111, polar = True) # plt.ylim([0, 30])a = 1 theta = np.linspace(-np.pi, np.pi, 200) x = a * np.sqrt(2) * np.cos(theta) / (np.sin(theta) ** 2 + 1) y = a * np.sqrt(2) * np.cos(theta) * np.sin(theta) / (np.sin(theta) ** 2 + 1) plt.plot(x, y, label = r'$ \rho^2=a^2cos2\theta \quad |a=1 $', linestyle = 'solid')plt.axis('equal') plt.legend() plt.show()

三葉玫瑰線 ρ=acos3θ\rho=acos3\thetaρ=acos3θρ=asin3θ\rho=asin3\theta ρ=asin3θ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal # plt.rcParams['figure.figsize'] = (8, 4.5) # plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) # plt.ylim([0, 30])a = 1 theta = np.linspace(0, 2 * np.pi, 200) rho = a * np.cos(3 * theta) plt.plot(theta, rho, label = r'$ \rho=acos3\theta \quad |a=1 $', linestyle = 'solid')# a = 2 # rho1 = a * rho # plt.plot(theta, rho1, label = r'$ \rho=acos3\theta \quad |a=2 $', linestyle = 'solid')a = 1 rho2 = a * np.sin(3 * theta) plt.plot(theta, rho2, label = r'$ \rho=asin3\theta \quad |a=1 $', linestyle = 'solid')plt.legend() plt.show()

四葉玫瑰線 ρ=acos2θ\rho=acos2\theta ρ=acos2θρ=asin2θ\rho=asin2\theta ρ=asin2θ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal # plt.rcParams['figure.figsize'] = (8, 4.5) # plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) # plt.ylim([0, 30])a = 1 theta = np.linspace(0, 2 * np.pi, 200) rho = a * np.cos(4 * theta) plt.plot(theta, rho, label = r'$ \rho=acos2\theta \quad |a=1 $', linestyle = 'solid')a = 2 rho1 = a * rho plt.plot(theta, rho1, label = r'$ \rho=acos2\theta \quad |a=2 $', linestyle = 'solid')# a = 1 # rho2 = a * np.sin(4 * theta) # plt.plot(theta, rho2, label = r'$ \rho=asin2\theta \quad |a=1 $', linestyle = 'solid')plt.legend() plt.show()

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal # plt.rcParams['figure.figsize'] = (8, 4.5) # plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) # plt.ylim([0, 30])theta = np.linspace(0, 2 * np.pi, 200)a = 1 rho = a * np.sin(4 * theta) plt.plot(theta, rho, label = r'$ \rho=asin2\theta \quad |a=1 $', linestyle = 'solid')a = 2 rho1 = a * np.sin(4 * theta) plt.plot(theta, rho1, label = r'$ \rho=asin2\theta \quad |a=2 $', linestyle = '--')plt.legend() plt.show()

多葉玫瑰線 ρ=acosnθ\rho=acosn\theta ρ=acosnθρ=asinnθ,∣n=1,2,3...\rho=asinn\theta,\quad|n=1,2,3...ρ=asinnθ,n=1,2,3...

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal # plt.rcParams['figure.figsize'] = (8, 4.5) # plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 plt.subplot(111, polar = True) # plt.ylim([0, 30])theta = np.linspace(0, 2 * np.pi, 200)a = 1 n = 20 rho = a * np.sin(10 * theta) plt.plot(theta, rho, label = r'$ \rho=asinn\theta \quad |a=1,n=10 $', linestyle = 'solid')plt.legend() plt.show()

函數(shù) 四葉線 x=aρsinθ,y=aρcosθ,ρ=2sinsin2θx=a\rho sin\theta,y=a\rho cos\theta, \rho = \sqrt{2}sin{sin2\theta}x=aρsinθ,y=aρcosθ,ρ=2?sinsin2θ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 # plt.subplot(111, polar = True) # plt.ylim([0, 30])a = 1 theta = np.linspace(-np.pi, np.pi, 200) rho = np.sqrt(2) * np.sin(np.sin(2*theta)) x = a * rho * np.sin(theta) y = a * rho * np.cos(theta) plt.plot(x, y, label = r'$x=a\rho sin\theta,y=a\rho cos\theta, \rho = \sqrt{2}sin{sin2\theta}$', linestyle = 'solid')plt.axis('equal') plt.legend() plt.show()

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-vELrwNwd-1589013522141)(output_52_0.svg)]

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal plt.rcParams['figure.figsize'] = (8, 4.5) plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 # plt.subplot(111, polar = True) # plt.ylim([0, 30])a = 1 theta = np.linspace(-np.pi, np.pi, 200) rho = np.sqrt(2) * np.sin(np.sin(4*theta)) x = a * rho * np.sin(theta) y = a * rho * np.cos(theta) plt.plot(x, y, label = r'$x=a\rho sin\theta,y=a\rho cos\theta, \rho = \sqrt{2}sin{sin2\theta}$', linestyle = 'solid')plt.axis('equal') plt.legend() plt.show()

函數(shù) 四葉線 x=aρsinθ,y=aρcosθ,ρ=2sin∣sin2θ∣x=a\rho sin\theta,y=a\rho cos\theta, \rho = \sqrt{2}sin{\vert sin2\theta \vert}x=aρsinθ,y=aρcosθ,ρ=2?sinsin2θ

%matplotlib inline %config InlineBackend.figure_format = "svg" import numpy as np import matplotlib.pyplot as plt from scipy import signal # plt.rcParams['figure.figsize'] = (8, 4.5) # plt.rcParams['figure.dpi'] = 150 plt.rcParams['font.sans-serif'] = ['Simhei'] #替代字體 plt.rcParams['axes.unicode_minus'] = False #解決坐標軸負數(shù)的鉛顯示問題#極坐標 # plt.subplot(111, polar = True) # plt.ylim([0, 30])a = 1 theta = np.linspace(-np.pi, np.pi, 1000) rho = np.sqrt(2) * np.sqrt(abs(np.sin(10*theta)) + 0.5) x = a * rho * np.sin(theta) y = a * rho * np.cos(theta) plt.plot(x, y, linestyle = 'solid')# label = r'$x=a\rho sin\theta,y=a\rho cos\theta, \rho = \sqrt{2}sin{sin2\theta}$',plt.axis('equal') # plt.legend() plt.show()

總結

以上是生活随笔為你收集整理的学习Python中用numpy与matplotlib遇到的一些数学函数与函数的绘图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。