"TiledChartLayout cannot be a parent." error message using pdeplot with tiledlayout

6 views (last 30 days)
I want to plot multiple solutions obtained with the PDE Modeling next to each other. Using subplot works just fine, but I want to use the more flexible tiledlayout command. However, this gives the error message "Error using uicontextmenu; TiledChartLayout cannot be a parent". Here's a MWA (the first few lines are just to have a solution to a PDE problem):
clear; close all
model = createpde;
geometryFromEdges(model,@lshapeg);
generateMesh(model);
applyBoundaryCondition(model,"dirichlet",Edge=1:model.Geometry.NumEdges,u=0);
specifyCoefficients(model,m=0, d=0, c=1, a=0, f=1);
results = solvepde(model);
% this works fine
subplot(1,2,1);
pdeplot(model,"XYData",results.NodalSolution);
subplot(1,2,2);
pdeplot(model,"XYData",results.NodalSolution);
% this one doesn't
figure;
tiledlayout(1,2);
nexttile;
pdeplot(model,"XYData",results.NodalSolution);
Error using uicontextmenu
TiledChartLayout cannot be a parent.

Error in pdeplot (line 1185)
hc=colorbar(ax,'UIContextMenu',uicontextmenu(ax.Parent)); % Disable context menu
nexttile;
pdeplot(model,"XYData",results.NodalSolution);
Any tips how to solve the issue?
  2 Comments
Matt J
Matt J on 5 Oct 2023
Edited: Matt J on 5 Oct 2023
I don't think there is a solution that would allow you to use tiledlayout. It would be helpful to know what tiledlayout functionality you are looking to use which you think subplot doesn't offer. There are many File Exchange tools designed to give similar functionality as tiledlayout, but using only the subplot framework.
Nicolas Schlosser
Nicolas Schlosser on 5 Oct 2023
Edited: Nicolas Schlosser on 5 Oct 2023
I guess I could use one of these workarounds. I wanted to reuse code from another project where tiledlayout worked as intended in order to create a common title and axes for the whole plot, like here: https://de.mathworks.com/matlabcentral/answers/499823-one-common-xlabel-and-ylabel-for-multiple-subplots . Also, I wanted to reduce the margins and make the whole image more compact. And since Matlab explicitly recommends using tiledlayout over subplot (as seen in the documentation of tiledlayout at https://de.mathworks.com/help/matlab/ref/tiledlayout.html ), I figured the two could be used interchangeably, or at least that subplot can in all cases be substituted with tiledlayout.

Sign in to comment.

Answers (1)

Matt J
Matt J on 5 Oct 2023
Edited: Matt J on 5 Oct 2023

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!