Geospatial Data Visualization
Basic Geospatial Plotting
Geographic coordinate system plotting example:
% Load geographic data
load coastlines
lat = coastlat;
lon = coastlon;
% Basic geospatial plotting
figure;
geoplot(lat, lon, 'LineWidth', 2, 'Color', [0.2 0.4 0.8]);
geobasemap('satellite'); % Set basemap
title('Global Coastlines (Satellite Basemap)');
% Add geographic markers
geoscatter(40.7128, -74.0060, 100, 'r', 'filled'); % New York coordinates
textm(40.7128, -74.0060, 'New York', 'FontSize', 12, 'Color', 'k');
Advanced geospatial analysis:
% Create geographic bubble chart
cities = readtable('world_cities.csv'); % Contains Lat/Lon/Population columns
figure;
geobubble(cities.Lat, cities.Lon, cities.Population/1e6, ...
'SizeLimits', [0 20], 'ColorScale', 'log');
geobasemap('colorterrain');
title('Global City Population Distribution (Log Scale)');
% Geographic heatmap
load earthquake_data % Contains Latitude/Longitude/Magnitude
figure;
geobubble(earthquake_data.Latitude, earthquake_data.Longitude, ...
earthquake_data.Magnitude, 'BubbleColorList', [0.8 0.2 0.2]);
geobasemap('redlands');
title('Earthquake Magnitude Distribution Heatmap');
Dynamic Geospatial Visualization
Time-series geographic animation:
% Load time-series geographic data
load hurricane_tracks % Contains Lat/Lon/Time arrays
% Create animation
figure;
h = geoplot(NaN, NaN, 'r-', 'LineWidth', 2); % Initialize empty plot
geobasemap('hybrid');
title('Hurricane Path Dynamic Demonstration');
axis tight manual; % Lock axes
% Animation frame update
for t = 1:size(hurricane_tracks,3)
geoplot(hurricane_tracks(:,:,t), 'r-', 'LineWidth', 2);
timestamp = datestr(hurricane_tracks(1,4,t), 'yyyy-mm-dd HH:MM');
title(sprintf('Hurricane Path - %s', timestamp));
drawnow;
pause(0.5);
end
Interactive Dashboard Development
App Designer Basics
Scientific dashboard construction:
% Create new App Designer project
function createDashboard()
% Main interface layout
app = uifigure('Name', 'Scientific Data Dashboard', 'Position', [100 100 1200 800]);
% Top control panel
controlPanel = uipanel(app, 'Title', 'Control Panel', 'Position', [0.01 0.85 0.98 0.14]);
uibutton(controlPanel, 'Text', 'Load Data', 'Position', [10 10 100 30], ...
'ButtonPushedFcn', @(btn,event) loadData(app));
% Central plotting area
plotArea = uipanel(app, 'Title', 'Data Visualization', 'Position', [0.01 0.45 0.98 0.4]);
app.UIAxes = uiaxes(plotArea, 'Position', [0.1 0.1 0.8 0.8]);
% Bottom status bar
statusBar = uilabel(app, 'Text', 'Ready', 'Position', [10 10 200 22], ...
'HorizontalAlignment', 'left');
end
% Data loading callback function
function loadData(app)
[file, path] = uigetfile('*.csv');
if isequal(file,0)
return;
end
data = readtable(fullfile(path, file));
app.Data = data;
updatePlot(app);
app.StatusBar.Text = sprintf('Loaded: %s', file);
end
% Plot update function
function updatePlot(app)
if ~isfield(app, 'Data')
return;
end
plot(app.UIAxes, app.Data.Time, app.Data.Value);
xlabel(app.UIAxes, 'Time');
ylabel(app.UIAxes, 'Measurement Value');
title(app.UIAxes, 'Real-Time Data Monitoring');
grid(app.UIAxes, 'on');
end
Advanced Interactive Components
Dynamic filtering dashboard:
% Add interactive components in App Designer
function addInteractiveComponents(app)
% Filtering panel
filterPanel = uipanel(app, 'Title', 'Data Filtering', 'Position', [0.01 0.6 0.98 0.24]);
% Dropdown menu
app.RegionDropdown = uidropdown(filterPanel, ...
'Items', {'All', 'East China', 'North China', 'South China'}, ...
'Position', [10 120 100 30], ...
'ValueChangedFcn', @(src,event) filterData(app));
% Slider
app.ValueSlider = uislider(filterPanel, ...
'Limits', [0 100], 'Value', 50, ...
'Position', [150 120 200 3], ...
'ValueChangedFcn', @(src,event) filterData(app));
% Checkbox group
app.CheckBoxGroup = uicheckbox(filterPanel, ...
'Text', 'Show Trend Line', ...
'Value', true, ...
'Position', [400 120 100 22], ...
'ValueChangedFcn', @(src,event) updatePlot(app));
end
% Data filtering callback
function filterData(app)
region = app.RegionDropdown.Value;
threshold = app.ValueSlider.Value;
showTrend = app.CheckBoxGroup.Value;
filteredData = app.Data;
if ~strcmp(region, 'All')
filteredData = filteredData(strcmp(filteredData.Region, region), :);
end
filteredData = filteredData(filteredData.Value > threshold, :);
app.FilteredData = filteredData;
updatePlot(app, showTrend);
end
Scientific Plotting Techniques
Error Visualization
Advanced error bar application:
% Experimental data preparation
x = 1:10;
y = sin(x/2);
err = 0.1 + rand(1,10)*0.2; % Random error
% Basic error bar plot
figure;
errorbar(x, y, err, 'o-', 'LineWidth', 2, 'MarkerSize', 8);
xlabel('X-axis'); ylabel('Y-axis');
title('Experimental Data with Error Bars');
grid on;
% Advanced error bar configuration
figure;
h = errorbar(x, y, err, err, 'CapSize', 15, 'Color', [0.2 0.4 0.8]);
h.Marker = 'square';
h.MarkerFaceColor = 'r';
h.MarkerSize = 10;
title('Custom Error Bar Style');
Contour Plotting
Basic contour plot:
% Generate grid data
[X,Y] = meshgrid(-2:0.1:2, -2:0.1:2);
Z = X.*exp(-X.^2 - Y.^2);
% Basic contour plot
figure;
contour(X,Y,Z,20);
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
title('Basic Contour Plot');
% Filled contour plot
figure;
contourf(X,Y,Z,20);
colorbar;
colormap jet;
title('Filled Contour Plot');
% 3D surface and contour combination
figure;
subplot(1,2,1);
surf(X,Y,Z);
shading interp;
title('3D Surface Plot');
subplot(1,2,2);
contour3(X,Y,Z,20);
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Contour Plot');
% Professional scientific visualization example
load seamount % Undersea mountain dataset
figure;
scatter3(x,y,z,5,z,'filled');
colormap parula;
colorbar;
xlabel('Longitude');
ylabel('Latitude');
zlabel('Depth (m)');
title('3D Scatter Plot of Undersea Terrain');
view(45,30);
Graphics Export and Optimization
Vector Graphics Export Techniques
High-quality publication-level graphics:
% Create complex graphic
figure('Color','white');
t = linspace(0,2*pi,1000);
plot(t, sin(t), 'LineWidth', 2);
hold on;
plot(t, cos(t), 'r--', 'LineWidth', 2);
xlabel('Phase (radians)', 'FontSize', 12);
ylabel('Amplitude', 'FontSize', 12);
title('Comparison of Trigonometric Functions', 'FontSize', 14);
legend('sin(t)', 'cos(t)', 'Location', 'best');
grid on;
% Export as vector graphic
exportgraphics(gcf, 'trig_functions.pdf', ...
'ContentType', 'vector', ...
'Resolution', 300);
% Export as SVG (scalable vector graphic)
exportgraphics(gcf, 'trig_functions.svg', ...
'ContentType', 'vector');
% Resolution control example
print('trig_functions.tiff', '-dtiff', '-r600'); % 600dpi TIFF
Multi-subplot export optimization:
% Create multi-subplot layout
figure('Position', [100 100 1200 800]);
subplot(2,2,1);
plot(randn(100,1));
title('Subplot 1');
subplot(2,2,2);
histogram(randn(1000,1),20);
title('Subplot 2');
subplot(2,2,3);
heatmap(rand(10));
title('Subplot 3');
subplot(2,2,4);
geoplot(rand(10,1)*10, rand(10,1)*10, 'o');
geobasemap('satellite');
title('Subplot 4');
% Export entire graphic
exportgraphics(gcf, 'multi_panel_figure.pdf', ...
'ContentType', 'vector');
Dynamic Interaction Enhancement
UI controls integration example:
% Add dynamic controls in App Designer
function addDynamicControls(app)
% Parameter control panel
paramPanel = uipanel(app, 'Title', 'Analysis Parameters', 'Position', [0.01 0.3 0.98 0.34]);
% Slider group
app.SmoothSlider = uislider(paramPanel, ...
'Limits', [0 10], 'Value', 3, ...
'Position', [10 150 200 3], ...
'ValueChangedFcn', @(src,event) updateAnalysis(app));
% Checkbox group
app.DetrendCheckbox = uicheckbox(paramPanel, ...
'Text', 'Remove Trend', ...
'Value', false, ...
'Position', [10 100 100 22], ...
'ValueChangedFcn', @(src,event) updateAnalysis(app));
% Dropdown menu
app.MethodDropdown = uidropdown(paramPanel, ...
'Items', {'Linear Fit', 'Polynomial Fit', 'Spline Fit'}, ...
'Value', 'Linear Fit', ...
'Position', [150 100 150 30], ...
'ValueChangedFcn', @(src,event) updateAnalysis(app));
end
% Dynamic update callback
function updateAnalysis(app)
smoothParam = app.SmoothSlider.Value;
doDetrend = app.DetrendCheckbox.Value;
method = app.MethodDropdown.Value;
% Re-analyze data based on parameters
analyzedData = performAnalysis(app.Data, ...
'SmoothParam', smoothParam, ...
'Detrend', doDetrend, ...
'Method', method);
% Update plot
plot(app.UIAxes, analyzedData);
title(app.UIAxes, sprintf('Analysis Results (Smoothing Parameter: %.1f)', smoothParam));
end
Performance Optimization Techniques
Graphics Rendering Acceleration
Large-scale data plotting optimization:
% Large dataset plotting optimization techniques
load large_dataset % Contains 1e6 data points
% Method 1: Data downsampling
figure;
plot(downsample(x,100), downsample(y,100), 'LineWidth', 1);
title('Downsampled Plot (1:100)');
% Method 2: Use plotyy to handle dual Y-axis big data
figure;
[ax,h1,h2] = plotyy(x, y1, x, y2, 'plot');
set(ax(1), 'YColor', 'b');
set(ax(2), 'YColor', 'r');
set(h1, 'LineWidth', 1);
set(h2, 'LineWidth', 1);
title('Big Data Dual Y-Axis Plot');
% Method 3: Use WebGL acceleration
figure;
webgl('on');
scatter3(x,y,z,5,z,'filled');
colormap jet;
title('WebGL Accelerated 3D Scatter Plot');
Memory management best practices:
% Big data processing memory optimization
function processLargeData()
% Chunk processing for large data files
chunkSize = 1e6; % Process 1 million rows at a time
fid = fopen('huge_data.csv');
header = fgetl(fid); % Read header row
% Initialize result storage
results = [];
% Chunk reading and processing
while ~feof(fid)
dataChunk = textscan(fid, '%f%f%f', chunkSize, 'Delimiter', ',');
if isempty(dataChunk{1})
break;
end
% Process current data chunk
processedChunk = complexCalculation(dataChunk);
% Accumulate results
results = [results; processedChunk];
% Periodically clear memory
if mod(size(results,1),1e7)==0
clear tempVars;
pack; % Organize memory fragments
end
end
fclose(fid);
% Final result analysis
finalAnalysis(results);
end



