用Python繪制數(shù)學函數(shù)圖像 | 您所在的位置:網(wǎng)站首頁 › 屬鼠的住八樓怎么緩解 › 用Python繪制數(shù)學函數(shù)圖像 |
博客文章: https://blog.manchan/post/Drawing-mathematical-function-images-with-Python/可在此處找到我 前言最近開始學習數(shù)學了,有一些題目的函數(shù)圖像非常有特點,有一些函數(shù)圖像手繪比較麻煩,那么有沒有什么辦法做出又標準又好看的數(shù)學函數(shù)圖像呢? 答案是有很多的,有很多不錯的軟件都能畫出函數(shù)圖像,但是,我想到了Python的數(shù)據(jù)可視化。Python在近些年非常火熱,在數(shù)據(jù)分析以及深度學習等方面得到廣泛地運用,其豐富的庫使其功能愈加強大。 這里我們使用Python的NumPy庫以及Matplotlib庫進行繪圖。 NumPy與MatplotlibNumPy(Numerical Python) 是 Python 語言的一個擴展程序庫,支持大量的維度數(shù)組與矩陣運算,此外也針對數(shù)組運算提供大量的數(shù)學函數(shù)庫。 Matplotlib 是 Python 的繪圖庫。 它可與 NumPy 一起使用,提供了一種有效的 MatLab 開源替代方案。 函數(shù)繪圖 所需庫函數(shù)語法 import 語句想使用 Python 源文件,只需在另一個源文件里執(zhí)行 import 語句,語法如下: import module1[, module2[,... moduleN] from … import 語句Python 的 from 語句讓你從模塊中導(dǎo)入一個指定的部分到當前命名空間中,語法如下: from modname import name1[, name2[, ... nameN]] numpy.arangenumpy 包中的使用 arange 函數(shù)創(chuàng)建數(shù)值范圍并返回 ndarray 對象,函數(shù)格式如下: numpy.arange(start, stop, step, dtype)根據(jù) start 與 stop 指定的范圍以及 step 設(shè)定的步長,生成一個 ndarray。 參數(shù)說明: 參數(shù)描述start起始值,默認為0stop終止值(不包含)step步長,默認為1dtype返回ndarray的數(shù)據(jù)類型,如果沒有提供,則會使用輸入數(shù)據(jù)的類型。 numpy.linspacenumpy.linspace 函數(shù)用于創(chuàng)建一個一維數(shù)組,數(shù)組是一個等差數(shù)列構(gòu)成的,格式如下: np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)參數(shù)說明: 參數(shù)描述start序列的起始值stop序列的終止值,如果endpoint為true,該值包含于數(shù)列中num要生成的等步長的樣本數(shù)量,默認為50endpoint該值為 true 時,數(shù)列中包含stop值,反之不包含,默認是True。retstep如果為 True 時,生成的數(shù)組中會顯示間距,反之不顯示。dtypendarray 的數(shù)據(jù)類型 導(dǎo)入所需模塊 import numpy as np from matplotlib import pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] #用來正常顯示中文標簽 plt.rcParams['axes.unicode_minus'] = False #用來正常顯示負號 一元一次函數(shù) # 一元一次函數(shù)圖像 x = np.arange(-10, 10, 0.1)#生成等差數(shù)組 y = 2 * x plt.xlabel('x') plt.ylabel('y') plt.title("一元一次函數(shù)") plt.plot(x, y) plt.show() |
今日新聞 |
推薦新聞 |
專題文章 |
CopyRight 2018-2019 實驗室設(shè)備網(wǎng) 版權(quán)所有 |