How to Set Axis Limits for an Added Graph in MATLAB?

In summary: Your Name]In summary, to set the tickmarks and limits for the added graph h3 in MATLAB, you can use the 'YAxisLocation' property of the axes object. This will sync the tickmarks and limits for h2 and h3.
  • #1
TimFys
3
0
Hi,
I am plotting 3 graphs in MATLAB using plotyy as

[ax h1 h2] = plotyy(x1,Ftemp,x2,Fsnow);
hold(ax(2), 'on');
h3 = plot(ax(2),x1,Fprec);

I am thus adding the third graph to the right hand y-axis. I then set the limits and tickmarks for the right hand y-axis as

set(ax(2), 'xlim', [1999.5 2010.5]);
set(ax(2), 'ylim', [0 50], 'YTick', 0:10:50);

This however only sets the y-axis for h2, the graph I originally plotted using plotyy. The added graph h3 has its own tickmarks and limits. Does anyone know how to handle the axis of h3, the added graph? I want the tickmarks of h2 and h3 to sync and be in the same range.

Thanks, Tim
 
Physics news on Phys.org
  • #2



Hi Tim,

To set the tickmarks and limits for the added graph h3, you can use the 'YAxisLocation' property of the axes object. This property specifies the location of the y-axis for a particular graph. In your case, you can use the following code to set the tickmarks and limits for h3:

set(ax(2), 'YAxisLocation', 'right'); % sets the y-axis location for h3 to the right side
set(ax(2), 'ylim', [0 50], 'YTick', 0:10:50); % sets the tickmarks and limits for h3

This should sync the tickmarks and limits for h2 and h3. Let me know if you have any further questions or if this solution works for you.

 

1. How do I set the axis limits in MatLab?

To set the axis limits in MatLab, you can use the xlim and ylim functions. These functions take in a vector containing the minimum and maximum values for the x-axis and y-axis, respectively. For example, if you want the x-axis to range from 0 to 10 and the y-axis to range from 0 to 20, you would use xlim([0 10]) and ylim([0 20]).

2. Can I set the axis limits to automatically fit my data in MatLab?

Yes, you can use the axis function to automatically set the axis limits to fit your data. This function takes in a vector containing the minimum and maximum values for the x-axis and y-axis, respectively, and it adjusts the axis limits accordingly. For example, if your data ranges from -5 to 5 on the x-axis and from 0 to 10 on the y-axis, you would use axis([-5 5 0 10]).

3. How do I change the axis limits for specific axes in a subplot?

If you have multiple axes in a subplot and want to set different axis limits for each one, you can use the set function. This function takes in the handle of the specific axes you want to modify and the axis limits you want to set. For example, if you have three axes in a subplot and want the first axis to range from -10 to 10, the second axis to range from 0 to 5, and the third axis to range from -5 to 5, you would use set(ax1, 'XLim', [-10 10]), set(ax2, 'XLim', [0 5]), and set(ax3, 'XLim', [-5 5]).

4. How do I set the same axis limits for all axes in a subplot?

To set the same axis limits for all axes in a subplot, you can use the axis function with the all keyword. This will apply the same axis limits to all axes in the current figure. For example, if you want all axes to range from 0 to 10, you would use axis([0 10 0 10], 'all').

5. Can I set the axis limits to be logarithmic in MatLab?

Yes, you can use the xscale and yscale functions to set the x-axis and y-axis to be logarithmic, respectively. These functions take in a string specifying the type of logarithmic scale you want to use, such as 'log' for a base 10 logarithmic scale or 'log2' for a base 2 logarithmic scale. For example, to set the x-axis to be logarithmic, you would use xscale('log').

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
565
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top