File Exchange Pick of the Week

March 3rd, 2008

Advanced MATLAB: Subplots

The distinction between MATLAB Basics and Advanced MATLAB is a somewhat arbitrary distinction. The heuristic I use is “If I knew it before I came to The MathWorks, it is basic.” It is as good of a rule as any.

Some might argue this is a more basic post, but the inclusion of the gotcha and the use of property value pairs made this an advanced topic in my mind.

This short video shows how to put multiple subplots on a figure. Axes of different sizes can be laid out. The use of the position property is covered. A common gotcha is shown also where one axis overlapping another will delete the first.

Video Content

iconFiles.jpgiconPod.jpglazy.jpg

15 Responses to “Advanced MATLAB: Subplots”

  1. Doug replied on :

    It was just pointed out that there is a typo at two minutes into the video. The title of the subplot on the right should be:

    h=subplot(‘position’, [0.6 0.1 0.3 0.8])

    Sorry!
    Doug

  2. Antunes replied on :

    Hi,

    Could you please give code to plot say 2 subplots side-by-side with the axes obeying the golden ratio?

    thanks
    a.

  3. Doug replied on :

    Antunes,

    You should be able to do that with the ‘position’ property value pair. Just get the length and width in ratio and then position appropriately.

    Doug

  4. Bassam Awad replied on :

    Hello,

    I am trying to plot data in 393 plots with each figure include 25 plots. Any help is really appreciated.

  5. Doug replied on :

    Bassam,

    That seems a little extreme to have 393 plot windows open. Having more than a dozen windows open in a Windows OS seems difficult to manage. I would try to think of a more effective way to display your data.

    Maybe a GUI that allows you to select the graph you are interested in would be better. Maybe an animation is more what you need.

    Doug

  6. Dimitrij replied on :

    thanks for the hint: I finally understood the “position” command applied to subplot, and that dimensions are given in percentage of figure width and height.

  7. Fikri replied on :

    Hi Doug,

    got a simple question here, I’m making an interface for an image compression project. I needed to generate several subplots for the histogram, but here lies the problem. After generating all the subplots (which I put inside a panel, not axes) I simply can’t remove/clear/reset those subplots, which I need to do to make my ‘Clear’ pushbutton works as it is assigned to do.

    a quick reply would be nice..

    regards

    Fikri

  8. Bob replied on :

    Fikri, see CLA.

  9. jitendra replied on :

    Hai Doug

    I need your help in plotting a time-series data set and in the form of sub-plots.My domain size is 362 X 181 and like that there are 12 data sets.I need to plot all these 12 data sets of same dimension and animate later.
    I need to make a script so that,it is operational.

    I strucked from last four days to do this.
    Thanking you in advance

    regards
    jitendra

  10. Doug replied on :

    jitendra,

    I am not sure I understand your question. Please contact support for help.

    Doug

  11. S. G. Poss replied on :

    With this nice demo, I now know what my problem is (something is overlaping), causing the first title not to be displayed and all titles moved up one histogram, with the last without a title.

    The question is: how do you solve this problem?

    I’ve shortened the titles as much as possible, but to no avail?

    Suggestions?

    The property section of the subplots is not thorough in the documentation and I note that the relative order of property statements can also produce bilwildering results.

    Looks like an area that needs some work or at least more documentation to allow workers to work around such problems.

    Thank you.

  12. Doug replied on :

    S.G.

    I am not sure what you are talking about. It is much better for us to be able to help if you can show the shortest code snippet that will reproduce the behavior.

    Thanks,
    Doug

  13. Rashmish replied on :

    Hi Doug,

    I have a problem in Matlab, and I hope you can help me with it. I am solving a Differential Equation in Matlab using Matlab’s own functions, for different values of some parameters. For some values of the parameter, it takes too long and I stop the program by a Ctrl-C manually, and then change the parameter.
    Is there a way to automate this? i.e., the program should itself figure out that it took more than say some specific amount of time and so it should move to the next parameter.
    I hope you got the question.
    Your comments would be greatly appreciated !
    Thanks in advance.

    Rashmish

  14. Steve L replied on :

    Rashmish,

    There’s no “timeout” capability for the ODE solvers. However, it sounds like the stiffness of your ODEs may depend on the parameters. Cleve wrote a column on ODEs and stiffness here:

    http://www.mathworks.com/company/newsletters/news_notes/clevescorner/may03_cleve.html

    You should try switching your program to use a stiffer solver to try to reduce the amount of time it takes to solve the ODE when it’s stiff. There’s a table in the function reference page for the ODE solvers that describes which solvers are stiff solvers and which aren’t.

    http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ode113.html?BB=1

    If you’re currently using ODE45, try ODE15S or ODE23S.

  15. Rashmish replied on :

    I finished my work by the manual bull-work, but it wd still be helpful to know if there is any way at all. I am solving a BVP; I don’t know if your comments on stiffness would still help. Do you have some other suggestions about my problem?

    Thanks

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

These postings are the author's and don't necessarily represent the opinions of The MathWorks.