How to change the subplot positioning in an existing figure? (2024)

101 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

Lenwo am 25 Jun. 2017

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure

Bearbeitet: dpb am 26 Jun. 2017

Akzeptierte Antwort: Jan

In MATLAB Online öffnen

Dear experts,

a while ago I created a figure with two subplots in the configuration subplot(1,2,x) (one row, two columns). I saved the figure as 'fig' file for later use. Now I would prefer the plots to be in subplot(2,1) (two rows, one column) configuration. I only have the .fig file and have no access to the relevant data to replot the figure.

Is there a way the accomplish this?

I opened the figure and tried the following:

hF = gcf;

hSub11 = subplot(1,2,1);

hSub12 = subplot(1,2,2);

nF = figure;

hSub21 = subplot(2,1,1);

copyobj(allchild(hSub11),hSub21)

hSub22 = subplot(2,1,2);

copyobj(allchild(hSub12),hSub22)

But besides the legends, titles and axis labels are missing, the plots show white spaces on top and bottom or left and right of the figure, especially when being resized.

Does anyone have an advice or an overall better solution for me?

Thank you very much! (I am using MATLAB 2014b)

3 Kommentare

1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden

dpb am 25 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464315

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464315

You can try the 'legacy' option to see if it helps but I'm guessing probably won't be fully satisfactory, either...there's just too much "behind the scenes" stuff going on...

Don't show us what the plots are, but I'm guessing the only real way will be to retrieve the data from the existing plots and recreate them.

Lenwo am 25 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464337

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464337

Thanks for your reply! That's an good idea, I will try this. I hope things won't get more complicated since I am using contour plots.

dpb am 25 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464346

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464346

Can you build a sample that duplicates this that can post that folks can play with easily?

I've not tried Jan's idea; I can see why it didn't do what you expected exactly as is, but it may be able to be made to do so...I'll poke around little and try something.

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Jan am 25 Jun. 2017

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#answer_271906

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#answer_271906

Bearbeitet: Jan am 25 Jun. 2017

In MATLAB Online öffnen

This swaps the positions of the two axes:

hFig = gcf;

hAxes = findobj(allchild(hFig), 'flat', 'Type', 'axes');

axesPos = get(hAxes, 'Position');

set(hAxes(1), 'Position', axesPos{2});

set(hAxes(2), 'Position', axesPos{1});

[EDITED] Thismove the first axes to the subplot(2,1,1) position, the 2nd to (2,1,2):

hFig = gcf;

hAxes = findobj(allchild(hFig), 'flat', 'Type', 'axes');

hSub = subplot(2,1,1);

set(hAxes(1), 'Position', get(hSub, 'Position'));

delete(hSub);

hSub = subplot(2,1,2);

set(hAxes(2), 'Position', get(hSub, 'Position'));

delete(hSub);

Please try it and explain, how the legends, white spaces etc. are effects.

Did you try to use the property editor? Open the figure, activate the toolbar, click on the arrow and move the objects around or resize with the mouse.

5 Kommentare

3 ältere Kommentare anzeigen3 ältere Kommentare ausblenden

Lenwo am 25 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464336

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464336

Thanks for your reply! But this Code does only switch the plots, but they remain in two columns, one row.

Jan am 25 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464350

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464350

Bearbeitet: dpb am 26 Jun. 2017

Sorry, I misunderstood the question. See EDITED.

dpb am 26 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464359

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464359

In MATLAB Online öffnen

I got sidetracked, but that's the answer, Jan. :)

Can be done with

for i=1:2, hAxRef(i)=subplot(1,2,i); end % create reference positions

set(hAxes,{'position'},{hAxRef.Position}.')

using the cell notation to set multiple properties at one call.

Lenwo am 26 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464413

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464413

Bearbeitet: Lenwo am 26 Jun. 2017

In MATLAB Online öffnen

Hey Jan and dpb, thank you very much, it worked out for me. I combined your answers and rescaled the axes since the countour legends were cut off. That's what I finally came up with:

hFig = gcf;

hAxes = findobj(allchild(hFig), 'flat', 'Type', 'axes');

hTempFig = figure;

for i=1:2, hAxRef(i)=subplot(2,1,3-i); end % create reference positions

set(hAxes,{'position'},{hAxRef.Position}.')

delete(hTempFig);

axPosition = hAxes(1).Position;

set(hAxes(1), 'Position', [axPosition(1) axPosition(2) axPosition(3)-0.15 axPosition(4)]);

axPosition = hAxes(2).Position;

set(hAxes(2), 'Position', [axPosition(1) axPosition(2) axPosition(3)-0.15 axPosition(4)]);

I bet there is a more efficient way for the rescaling part, but it works just fine!

Thanks again!!

dpb am 26 Jun. 2017

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464467

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/346178-how-to-change-the-subplot-positioning-in-an-existing-figure#comment_464467

Bearbeitet: dpb am 26 Jun. 2017

Welcome, Jan got me to realize it would work that way; I initially was thinking about the subplot behavior that would delete the underlying axes if another occludes an existing one's position -- but at the lower level of directly manipulating the 'position' vectors there's no checking that that occurs...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABGraphics2-D and 3-D Plots

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

  • subplot
  • figure
  • axis
  • replot

Produkte

  • MATLAB

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by How to change the subplot positioning in an existing figure? (11)

How to change the subplot positioning in an existing figure? (12)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • 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
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

How to change the subplot positioning in an existing figure? (2024)
Top Articles
Chase Claypool Stats, News and Video - WR | NFL.com
Balance Druid PvP Talents and Builds (The War Within (11.0.2))
Funny Roblox Id Codes 2023
Golden Abyss - Chapter 5 - Lunar_Angel
Www.paystubportal.com/7-11 Login
Joi Databas
DPhil Research - List of thesis titles
Shs Games 1V1 Lol
Evil Dead Rise Showtimes Near Massena Movieplex
Steamy Afternoon With Handsome Fernando
Which aspects are important in sales |#1 Prospection
Detroit Lions 50 50
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Grace Caroline Deepfake
978-0137606801
Nwi Arrests Lake County
Justified Official Series Trailer
London Ups Store
Committees Of Correspondence | Encyclopedia.com
Pizza Hut In Dinuba
Jinx Chapter 24: Release Date, Spoilers & Where To Read - OtakuKart
How Much You Should Be Tipping For Beauty Services - American Beauty Institute
Free Online Games on CrazyGames | Play Now!
Sizewise Stat Login
VERHUURD: Barentszstraat 12 in 'S-Gravenhage 2518 XG: Woonhuis.
Jet Ski Rental Conneaut Lake Pa
Unforeseen Drama: The Tower of Terror’s Mysterious Closure at Walt Disney World
Ups Print Store Near Me
C&T Wok Menu - Morrisville, NC Restaurant
How Taraswrld Leaks Exposed the Dark Side of TikTok Fame
Dashboard Unt
Access a Shared Resource | Computing for Arts + Sciences
Speechwire Login
Restored Republic
3473372961
Craigslist Gigs Norfolk
Litter-Robot 3 Pinch Contact & DFI Kit
Moxfield Deck Builder
Senior Houses For Sale Near Me
Montrose Colorado Sheriff's Department
Whitehall Preparatory And Fitness Academy Calendar
Trivago Myrtle Beach Hotels
Anya Banerjee Feet
Three V Plymouth
FREE - Divitarot.com - Tarot Denis Lapierre - Free divinatory tarot - Your divinatory tarot - Your future according to the cards! - Official website of Denis Lapierre - LIVE TAROT - Online Free Tarot cards reading - TAROT - Your free online latin tarot re
Thotsbook Com
Vérificateur De Billet Loto-Québec
Funkin' on the Heights
Vci Classified Paducah
Www Pig11 Net
Ty Glass Sentenced
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 5277

Rating: 4.6 / 5 (66 voted)

Reviews: 89% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.