在MATLAB中给子图(subplot)增加一个总标题

有两个函数 suptitlesgtitle,这两个函数均可以实现给子图(subplot)添加标题,但是优先使用sgtitlesuptitle使用起来存在问题,当子图多了以后,使用suptitle会导致第一个和第二个子图的形状变形,缩小了。

 

【优先使用sgtitle,但是该函数在2018b中推出的】

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
最新发布
07-24
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值