Matlab、Python為工具解析數(shù)據(jù)可視化之美
在我們科研、工作中,將數(shù)據(jù)完美展現(xiàn)出來尤為重要。
數(shù)據(jù)可視化是以數(shù)據(jù)為視角,探索世界。我們真正想要的是 — 數(shù)據(jù)視覺,以數(shù)據(jù)為工具,以可視化為手段,目的是描述真實(shí),探索世界。
下面介紹一些數(shù)據(jù)可視化的作品(包含部分代碼),主要是地學(xué)領(lǐng)域,可遷移至其他學(xué)科。
Example 1 :散點(diǎn)圖、密度圖(Python)
import numpy as np
import matplotlib.pyplot as plt
# 創(chuàng)建隨機(jī)數(shù)
n = 100000
x = np.random.randn(n)
y = (1.5 * x) + np.random.randn(n)
fig1 = plt.figure()
plt.plot(x,y,'.r')
plt.xlabel('x')
plt.ylabel('y')
plt.savefig('2D_1V1.png',dpi=600)
nbins = 200
H, xedges, yedges = np.histogram2d(x,y,bins=nbins)
# H needs to be rotated and flipped
H = np.rot90(H)
H = np.flipud(H)
# 將zeros mask
Hmasked = np.ma.masked_where(H==0,H)
# Plot 2D histogram using pcolor
fig2 = plt.figure()
plt.pcolormesh(xedges,yedges,Hmasked)
plt.xlabel('x')
plt.ylabel('y')
cbar = plt.colorbar()
cbar.ax.set_ylabel('Counts')
plt.savefig('2D_2V1.png',dpi=600)
plt.show()


Example 2 :雙Y軸(Python)
import csv
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
data=pd.read_csv('LOBO0010-2020112014010.tsv',sep='\t')
time=data['date [AST]']
sal=data['salinity']
tem=data['temperature [C]']
print(sal)
DAT = []
for row in time:
DAT.append(datetime.strptime(row,"%Y-%m-%d %H:%M:%S"))
#create figure
fig, ax =plt.subplots(1)
# Plot y1 vs x in blue on the left vertical axis.
plt.xlabel("Date [AST]")
plt.ylabel("Temperature [C]", color="b")
plt.tick_params(axis="y", labelcolor="b")
plt.plot(DAT, tem, "b-", linewidth=1)
plt.title("Temperature and Salinity from LOBO (Halifax, Canada)")
fig.autofmt_xdate(rotation=50)
# Plot y2 vs x in red on the right vertical axis.
plt.twinx()
plt.ylabel("Salinity", color="r")
plt.tick_params(axis="y", labelcolor="r")
plt.plot(DAT, sal, "r-", linewidth=1)
#To save your graph
plt.savefig('saltandtemp_V1.png' ,bbox_inches='tight')
plt.show()

Example 3:擬合曲線(Python)
import csv
import numpy as np
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
import scipy.signal as signal
data=pd.read_csv('LOBO0010-20201122130720.tsv',sep='\t')
time=data['date [AST]']
temp=data['temperature [C]']
datestart = datetime.strptime(time[1],"%Y-%m-%d %H:%M:%S")
DATE,decday = [],[]
for row in time:
daterow = datetime.strptime(row,"%Y-%m-%d %H:%M:%S")
DATE.append(daterow)
decday.append((daterow-datestart).total_seconds()/(3600*24))
# First, design the Buterworth filter
N = 2 # Filter order
Wn = 0.01 # Cutoff frequency
B, A = signal.butter(N, Wn, output='ba')
# Second, apply the filter
tempf = signal.filtfilt(B,A, temp)
# Make plots
fig = plt.figure()
ax1 = fig.add_subplot(211)
plt.plot(decday,temp, 'b-')
plt.plot(decday,tempf, 'r-',linewidth=2)
plt.ylabel("Temperature (oC)")
plt.legend(['Original','Filtered'])
plt.title("Temperature from LOBO (Halifax, Canada)")
ax1.axes.get_xaxis().set_visible(False)
ax1 = fig.add_subplot(212)
plt.plot(decday,temp-tempf, 'b-')
plt.ylabel("Temperature (oC)")
plt.xlabel("Date")
plt.legend(['Residuals'])
plt.savefig('tem_signal_filtering_plot.png', bbox_inches='tight')
plt.show()

Example 4:三維地形(Python)
# This import registers the 3D projection
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cbook
from matplotlib import cm
from matplotlib.colors import LightSource
import matplotlib.pyplot as plt
import numpy as np
filename = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
with np.load(filename) as dem:
z = dem['elevation']
nrows, ncols = z.shape
x = np.linspace(dem['xmin'], dem['xmax'], ncols)
y = np.linspace(dem['ymin'], dem['ymax'], nrows)
x, y = np.meshgrid(x, y)
region = np.s_[5:50, 5:50]
x, y, z = x[region], y[region], z[region]
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'))
ls = LightSource(270, 45)
rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,
linewidth=0, antialiased=False, shade=False)
plt.savefig('example4.png',dpi=600, bbox_inches='tight')
plt.show()

Example 5:三維地形,包含投影(Python)

Example 6:切片,多維數(shù)據(jù)同時(shí)展現(xiàn)(Python)

Example 7:SSH GIF 動(dòng)圖展現(xiàn)(Matlab)

Example 8:Glider GIF 動(dòng)圖展現(xiàn)(Python)

Example 9:渦度追蹤 GIF 動(dòng)圖展現(xiàn)

到此這篇關(guān)于數(shù)據(jù)可視化之美 -- 以Matlab、Python為工具的文章就介紹到這了,更多相關(guān)python數(shù)據(jù)可視化之美內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Python中seaborn庫之countplot的數(shù)據(jù)可視化使用
- python實(shí)現(xiàn)股票歷史數(shù)據(jù)可視化分析案例
- Python數(shù)據(jù)可視化之基于pyecharts實(shí)現(xiàn)的地理圖表的繪制
- 解決Python數(shù)據(jù)可視化中文部分顯示方塊問題
- python使用pyecharts庫畫地圖數(shù)據(jù)可視化的實(shí)現(xiàn)
- python代碼實(shí)現(xiàn)TSNE降維數(shù)據(jù)可視化教程
- Python數(shù)據(jù)可視化處理庫PyEcharts柱狀圖,餅圖,線性圖,詞云圖常用實(shí)例詳解
- Python數(shù)據(jù)可視化:餅狀圖的實(shí)例講解
相關(guān)文章
PyQt5 關(guān)于Qt Designer的初步應(yīng)用和打包過程詳解
Qt Designer中的操作方式十分靈活,其通過拖拽的方式放置控件可以隨時(shí)查看控件效果。這篇文章主要介紹了PyQt5 關(guān)于Qt Designer的初步應(yīng)用和打包,需要的朋友可以參考下2021-09-09
Python中Word文件自動(dòng)化操作小結(jié)
Python-docx是一個(gè)Python庫,提供了對(duì)Microsoft?Word(.docx文件)的讀寫和修改功能,本文主要介紹了如何使用Python-docx實(shí)現(xiàn)Word文件自動(dòng)化操作,需要的可以參考下2024-04-04
Django 路由層URLconf的實(shí)現(xiàn)
這篇文章主要介紹了Django 路由層URLconf的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
Python調(diào)用ChatGPT的API實(shí)現(xiàn)文章生成
最近ChatGPT大火,在3.5版本后開放了接口API,所以很多人開始進(jìn)行實(shí)操,這里我就用python來為大家實(shí)現(xiàn)一下,如何調(diào)用API并提問返回文章的說明2023-03-03
Python selenium使用autoIT上傳附件過程詳解
這篇文章主要介紹了Python selenium使用autoIT上傳附件過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
Python提取轉(zhuǎn)移文件夾內(nèi)所有.jpg文件并查看每一幀的方法
今天小編就為大家分享一篇Python提取轉(zhuǎn)移文件夾內(nèi)所有.jpg文件并查看每一幀的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-06-06
python使用pandas實(shí)現(xiàn)數(shù)據(jù)分割實(shí)例代碼
這篇文章主要介紹了python使用pandas實(shí)現(xiàn)數(shù)據(jù)分割實(shí)例代碼,介紹了使用pandas實(shí)現(xiàn)對(duì)dataframe格式的數(shù)據(jù)分割成時(shí)間跨度相等的數(shù)據(jù)塊,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-01-01

