You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to make contour to have the same axes
9 views (last 30 days)
Show older comments
I have a two different plots with 2 different axes. The second plot (fig2) is extracted from the first plot (fig1).
Please how can I make the extract plot to have the same axis as the first one. I tried aspect ratio function but couldn't work.
openfig('fig1.fig');
openfig('fig2.fig');
11 Comments
Cris LaPierre
on 9 Feb 2024
Please share the code you used to create both plots.
Are you saying fig2 should keep the axes as labeled, with the plot filling the figure window, or should the figure essentially be zoomed to the exact borders of the contour plot so that it fills the figure window?
University
on 9 Feb 2024
Thank you Cris. Not really zooming it. I think I was able to zoom it with your assitance last week but that wasn't what I wanted. I want the fig2 to plot fill the figure window.
University
on 9 Feb 2024
See code:
fig2 = figure(2);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fig2 = figure(2);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
% axis label
xlabel('HAN region length, $l$ [m]','Interpreter','latex');
ylabel('activity, $\xi$','Interpreter','latex');
xlim([pars.W/1000, pars.W/3])
ylim([0, 125])
I set the limit of fig2 using the axix of fig1.
Cris LaPierre
on 9 Feb 2024
Edited: Cris LaPierre
on 9 Feb 2024
The reason it is not filling the axes is because you have set the limits of fig2 to be the same as fig1. If fig2 is indeed a subset of fig1, then you need to use the limits of the data in fig2 to set the axes limits. Otherwise, you are plotting it the same size it was in the original figure. Where there is no data remains white.
University
on 9 Feb 2024
Edited: Torsten
on 9 Feb 2024
Yeah I understand what you mean. This is the actual figure without setting the limit.
openfig('fig2_actual.fig');
Cris LaPierre
on 9 Feb 2024
Also, I think you copied the same code twice rather than code that creates the 2 figures you attached.
University
on 9 Feb 2024
The figures are coded differently. I added more points around the isolated maxumum to extract more information.
University
on 9 Feb 2024
% axis for first figure
xivals = linspace(0, 125, 20);
Lvals = linspace(2e-8, 6.6667e-6, 20);
% axis for second figure
xivals = linspace(47.8947, 123.158, 20);
Lvals = linspace(7.19649e-07, 3.51825e-06, 20);
I have attached data for each of the figures
Cris LaPierre
on 9 Feb 2024
Edited: Cris LaPierre
on 9 Feb 2024
Can you update your post to use the tools in the ribbon to create formatted code, and then run that code so that it creates each figure here? Smiilar to what I did here.
University
on 9 Feb 2024
Edited: Torsten
on 9 Feb 2024
load data_0_125.mat
figure;
xi = linspace(0, 125,20);
L=linspace(2e-08, 6.66666666666667e-06, 20);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
hold on
for i=1:length(L)
for j=1:length(xi)
plot(L(i), xi(j), 'w.', 'LineWidth', 2, 'MarkerSize', 5)
end
end
set(gca,'clim',[min(min(intul)) max(max(intul))]);
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
$\int u_L \mathrm{dz} $
String scalar or character vector must have valid interpreter syntax:
$\int u_L \mathrm{dz} $
%%%%%
load data_xi_48_123.mat
figure;
xivals = linspace(47.8947, 123.158, 20);
Lvals = linspace(7.19649e-07, 3.51825e-06, 20);
[C,h] = contourf(L, xi, intul, [min(min(intul)):0.05e-11:max(max(intul))],'ShowText','off','edgecolor','none');
c = colorbar;
c.TickLabelInterpreter='latex';
c.Label.String = '$\int u_L \mathrm{dz} $';
c.Label.Interpreter = 'latex';
colormap jet
clabel(C,h)
set(gca,'clim',[min(min(intul)) max(max(intul))]);
Warning: Error updating Text.
String scalar or character vector must have valid interpreter syntax:
$\int u_L \mathrm{dz} $
String scalar or character vector must have valid interpreter syntax:
$\int u_L \mathrm{dz} $
Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)