In our scientific research , at work , It is particularly important to show the data perfectly .
Data visualization is based on data , Explore the world . What we really want is — Data vision , Data based tools , By means of visualization , The purpose is to describe reality , Explore the world .
Here are some data visualization works ( Contains part of the code ), Mainly in the field of Geosciences , Can be transferred to other disciplines .
Example 1 : Scatter diagram , Density map (Python)
import numpy as np import matplotlib.pyplot as plt # Create random number 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) # take 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 : double Y axis (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: Fitting curve (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: 3D Terrain (Python)
# This import registers the 3D projection from mpl_toolkits.mplot3d import
Axes3D from matplotlibimport cbook from matplotlib import cm from
matplotlib.colorsimport 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: 3D Terrain , Include projection (Python)
Example 6: section , Simultaneous presentation of multidimensional data (Python)
Example 7:SSH GIF Dynamic graph display (Matlab)
Example 8:Glider GIF Dynamic graph display (Python)
Example 9: Vorticity tracking GIF Dynamic graph display
Technology