国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Python可視化.1
https://matplotlib.org/stable/tutorials/introductory/usage.html#sphx-glr-tutorials-introductory-usage-py
數(shù)學(xué)建模比賽和平時(shí)的算法研究中,數(shù)據(jù)可視化是一個(gè)非常好的學(xué)習(xí)方式,可以直觀的看出數(shù)據(jù)內(nèi)在之間的聯(lián)系,但是繪圖是一個(gè)極其系統(tǒng)的工程,隨便學(xué)學(xué)感覺(jué)沒(méi)有什么意思,要學(xué)就系統(tǒng)的學(xué)。首先學(xué)Matplotib,已經(jīng)成為一種py上面的標(biāo)準(zhǔn)繪圖庫(kù)。

import matplotlib.pyplot as pltimport numpy as np
fig, ax = plt.subplots() # 創(chuàng)建一個(gè)畫布ax.plot( [1, 2, 3, 4], [1, 4, 2, 3])這個(gè)代碼是
import matplotlib.pyplot as plt import numpy as np
plt.plot( [1,2,3,4], [1,4,2,3])

以上兩個(gè)代碼都是可以生成同樣的圖像

第二個(gè)代碼對(duì)于matlab的使用者來(lái)說(shuō)應(yīng)該是熟悉的

在文檔的開篇,學(xué)一個(gè)圖形構(gòu)成的元素很有必要

axs是軸的意思,就是在這個(gè)語(yǔ)境里面是坐標(biāo)軸的意思

為了學(xué)習(xí)方便我進(jìn)行了翻譯,部分我翻譯的不準(zhǔn)

比如spines,這個(gè)意思的原意思為脊柱

那我這里就引申為骨架

部分有未標(biāo)注的,這里補(bǔ)全

https://matplotlib.org/stable/api/axes_api.html#matplotlib.axes.Axes
import matplotlib.pyplot as pltimport numpy as np
# plt.plot([1, 2, 3, 4],[1, 4, 2, 3]# )fig = plt.figure()  # 一個(gè)無(wú)axe的空畫布fig, ax = plt.subplots()  # 一個(gè)大圖fig, axs = plt.subplots(22)  # 2X2的子圖

生成的圖樣



我們基礎(chǔ)知識(shí)就先說(shuō)這么多,我們來(lái)考慮更加現(xiàn)實(shí)的問(wèn)題。對(duì)于一個(gè)繪圖的流程怎么做?我這里給出自己的流程:


  1. 輸入

  2. 傳給繪圖單元

  3. 顯示



其實(shí)就是這么簡(jiǎn)單,而且這個(gè)過(guò)程是線性的,也是阻塞的。輸入要“干凈”,輸出才有保障。所以我們的主題轉(zhuǎn)入了->輸入。

期望輸入一個(gè)

數(shù)組或者是操作掩碼數(shù)組


掩碼是啥?

    在許多情況下,數(shù)據(jù)集可能不完整或因無(wú)效數(shù)據(jù)的存在而受到污染。例如,傳感器可能無(wú)法記錄數(shù)據(jù)或記錄無(wú)效值。numpy.ma模塊通過(guò)引入掩碼數(shù)組提供了一種解決此問(wèn)題的便捷方法。


再看一種解釋,數(shù)據(jù)很大形況下是凌亂的,并且含有空白的或者無(wú)法處理的字符,掩碼式數(shù)組可以很好的忽略殘缺的或者是無(wú)效的數(shù)據(jù)點(diǎn)。

掩碼式數(shù)組由一個(gè)正常數(shù)組與一個(gè)布爾式數(shù)組組成,若布爾數(shù)組中為Ture,則表示正常數(shù)組中對(duì)應(yīng)下標(biāo)的值無(wú)效,反之False表示對(duì)應(yīng)正常數(shù)組的值有效。

masked數(shù)組是標(biāo)準(zhǔn)numpy.ndarray和 masked的組合。掩碼是nomask,表示關(guān)聯(lián)數(shù)組的值無(wú)效,或者是一個(gè)布爾數(shù)組,用于確定關(guān)聯(lián)數(shù)組的每個(gè)元素是否有效。當(dāng)掩碼的元素為False時(shí),關(guān)聯(lián)數(shù)組的相應(yīng)元素有效,并且被稱為未屏蔽。當(dāng)掩碼的元素為True時(shí),相關(guān)數(shù)組的相應(yīng)元素被稱為被屏蔽(無(wú)效)。

import numpy.ma as ma
import numpy as npx = np.array( [1, 2, 3, 5, 7, 4, 3, 2, 9, 0])print(x)mask = x < 5mx = ma.array(x, mask=mask)print(mask)print(mx)

輸出的結(jié)果

看第二個(gè)的方法

掩碼數(shù)組具有三個(gè)屬性:data、mask、fill_value;

data表示原始數(shù)值數(shù)組,

mask表示獲得掩碼用的布爾數(shù)組,

fill_value表示的填充值替代無(wú)效值之>后的數(shù)組,該數(shù)組通過(guò)filled()方法查看;

https://numpy.org.cn/reference/routines/ma.html
https://numpy.org/doc/stable/reference/generated/numpy.array.html#numpy.array
https://numpy.org/doc/stable/reference/generated/numpy.ma.masked_array.html#numpy.ma.masked_array
https://github.com/numpy/numpy

在此之前安裝一下pandas

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 2, 100)print(x)
# Note that even in the OO-style, we use `.pyplot.figure` to create the figure.fig, ax = plt.subplots() # Create a figure and an axes.ax.plot(x, x, label='linear') # Plot some data on the axes.ax.plot(x, x**2, label='quadratic') # Plot more data on the axes...ax.plot(x, x**3, label='cubic') # 三次方ax.set_xlabel('x label') # Add an x-label to the axes.ax.set_ylabel('y label') # Add a y-label to the axes.ax.set_title("Simple Plot") # 添加標(biāo)題ax.legend() # 添加圖例

圖像的結(jié)果

x = np.linspace(0, 10, 10)

x = np.linspace(0, 10, 5)

x = np.linspace(0, 5, 5)


注意這些步長(zhǎng)的設(shè)置,可以讓你的圖更加的平緩

注意代碼之前的序列生成器, numpy.linspace()函數(shù)用于在線性空間中以均勻步長(zhǎng)生成數(shù)字序列。

語(yǔ)法格式: array = numpy.linspace(start, end, num=num_points)將在startend之間生成一個(gè)統(tǒng)一的序列,共有num_points個(gè)元素。

  • start -> Starting point (included) of the rangestart ->范圍的起點(diǎn)(包括)

  • end -> Endpoint (included) of the rangeend ->范圍的端點(diǎn)(包括)

  • num -> Total number of points in the sequencenum >序列中的總點(diǎn)數(shù)

import numpy as npimport matplotlib.pyplot as plty = np.zeros(5)print(y)x1 = np.linspace(0, 10, 5)print(x1)x2 = np.linspace(0, 10, 5)print(x2)plt.plot(x1, y, 'o')plt.plot(x2, y + 0.5, 'o')plt.ylim([-0.5, 1])plt.show()
import numpy as npimport matplotlib.pyplot as plty = np.zeros(5)print(y)x1 = np.linspace(0, 10, 5)print(x1)x2 = np.linspace(0, 10, 5)print(x2)plt.plot(x1, y, 'o')plt.plot(x2, y + 0.5, 'o')plt.ylim([-0.5, 1])plt.show()

注意linespace里面的取數(shù)

# import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 2, 10)y = np.linspace(0, 10, 5)
print(x)print("--------------------------------------------------")print(y)

你看都是浮點(diǎn)數(shù)的輸出


如果不想要最后的一個(gè)值,可以使用參數(shù)。

用關(guān)鍵字參數(shù)endpoint ,可以將其設(shè)置為False 。(默認(rèn)為True )

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)

這個(gè)函數(shù)的參數(shù)

import numpy as np

p = np.array([[1, 2], [3, 4]])print(p)q = np.array([[5, 6], [7, 8]])print("--------------------------------------------------------")print(q)r = np.linspace(p, q, 3, axis=0)print("--------------------------------------------------------")
print(r)
s = np.linspace(p, q, 3, axis=1)print("--------------------------------------------------------")
print(s)

最后這里,留個(gè)小尾巴。這個(gè)參數(shù)我有點(diǎn)沒(méi)有看懂

import matplotlib.pyplot as pltimport numpy as npx = np.linspace(0, 5, 5)# print(x)# Note that even in the OO-style, we use `.pyplot.figure` to create the figure.fig, ax = plt.subplots() # Create a figure and an axes.ax.plot(x, x, label='linear') # Plot some data on the axes.ax.plot(x, x**2, label='quadratic') # Plot more data on the axes...ax.plot(x, x**3, label='cubic') # 三次方ax.set_xlabel('x label') # Add an x-label to the axes.ax.set_ylabel('y label') # Add a y-label to the axes.ax.set_title("Simple Plot") # 添加標(biāo)題ax.legend() # 添加圖例
最后在整理一下繪制的流程圖:
  1. 要?jiǎng)澐謝軸的分度值,這個(gè)值取決于你的要求,我這里只說(shuō)x軸,因?yàn)槲覀円恢闭J(rèn)為是x就是屬于自變量

  2. 接著就是要選擇你寫代碼的時(shí)候,具體的一個(gè)風(fēng)格。是面向?qū)ο驩O,還是傳統(tǒng)的matlab繪制法。如果是想對(duì)繪制的圖有一個(gè)全局的控制的,建議前者

  3. 接著就是調(diào)用一個(gè)最重要的plot進(jìn)行繪圖

  4. 接著就是對(duì)整體的圖形一些修飾和美化


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
python的matplotlib的三角函數(shù)sin和cos的靜態(tài)作圖詳解
Python Matplotlib簡(jiǎn)易教程
python數(shù)據(jù)分析工具之 matplotlib詳解
硬肝!超詳細(xì)matplotlib基礎(chǔ)介紹?。?!
matplotlib in Ipython Notebook
Python實(shí)現(xiàn)曲線擬合操作示例【基于numpy,scipy,matplotlib庫(kù)】
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服