function visualizeTableMask(data,idx)
figure
imagesc(idx)
xticklabels(erase(data.Properties.VariableNames,"_"))
xticks(1:width(data))
xtickangle(-45)
ys = yticks;
yticklabels(cellstr(data.Time(ys)))
colormap gray
end
function plotEventCostsMap(data,threshold)
ev = ["Flood","Lightning","Tropical Storm","Hurricane",...
"Waterspout","Tornado"];
idx = ismember(string(data.event_type),ev) & ...
data.damage_total > threshold;
x = data(idx ,:);
x.weathercats = removecats(x.weathercats);
x = FillMissingLatLon(x);
figure
gb = geobubble(x,"begin_lat","begin_lon",...
"SizeVariable","damage_total","ColorVariable","weathercats");
gb.Title = "Storm Event Damage";
gb.SizeLegendTitle = "Damage Cost ($1000)";
gb.ColorLegendTitle = "Event Type";
gb.Basemap = "colorterrain";
end
function data = FillMissingLatLon(data)
stateLatLon = struct2table(shaperead("usastatehi"));
idx = find(ismissing(data.begin_lat) & ismissing(data.begin_lon) & ~ismissing(data.state) & ...
ismember(string(data.weathercats),["Tropical Storm","Hurricane",...
"Waterspout"]));
for ii = 1:length(idx)
sidx = lower(stateLatLon.Name) == lower(string(data.state(idx(ii))));
data.begin_lat(idx(ii)) = stateLatLon.LabelLat(sidx);
data.begin_lon(idx(ii)) = stateLatLon.LabelLon(sidx);
end
end
function plotEventCosts(data)
ev = ["Flood","Lightning","Tropical Storm","Hurricane",...
"Waterspout","Tornado"];
idx = ismember(string(data.event_type),ev) & ...
data.damage_total > 0;
x = data(idx ,:);
x.weathercats = removecats(x.weathercats);
warning("off","MATLAB:handle_graphics:Layout:NoPositionSetInTiledChartLayout")
% Create figure
t = tiledlayout(4,2,"TileSpacing","compact","Padding","compact"); %#ok
nexttile([1 2])
boxplot(x.damage_total,x.event_type)
ylabel("Damge Total ($)")
nexttile(3,[3 1])
gb = geobubble(x,"begin_lat","begin_lon",...
"SizeVariable","damage_total","ColorVariable","weathercats");
gb.Title = "Storm Event Damage Total";
gb.SizeLegendTitle = "Damage Cost ($1000)";
gb.ColorLegendTitle = "Event Type";
gb.Basemap = "colorterrain";
nexttile
histogram(x.damage_property)
title("Property Damage ($)")
nexttile
histogram(x.damage_crops)
title("Crop Damage ($)")
nexttile
scatter(x.damage_property,x.damage_crops,".");
xlabel("Property Damage ($)"); ylabel("Crop Damage ($)")
sgtitle("Damage by Event")
warning("on","MATLAB:handle_graphics:Layout:NoPositionSetInTiledChartLayout")
end
最新发布