Userhanu
Userhanu

Reputation: 149

How to get variable scales on y axis for same graph in matlab plotting?

I am working on matlab programming, my problem is that in the same graph on y axis i need to have variable scaling, for example from 0.1 to 1 i need to have a gap between scales 0.1, but after 1 I need to have scale gap of 2, is there some command available for the same?

Upvotes: 0

Views: 1463

Answers (3)

Dattaprasad
Dattaprasad

Reputation: 105

You can also try the idea of scaling one dataset so that it has a similar magnitude as the other data set. Here you can multiply one dataset by 100 (or any suitable scaling parameter), and then it will be similar in size to the other data set. In order to clearly mention which data has been scaled in the graph use the legend.

plot(x,data1,x,100*data2)
legend('data1','100*data2','location','southeast')

Hope this helps.

Upvotes: 0

Abhinav Kumar
Abhinav Kumar

Reputation: 21

Please use gca property of matlab. In gca you can set a variable as your scales. Make that variable by merging two different scales

x=[1:80];
y=[.1:.1:8];
figure
plot(x,y);

%First Scale
scale1=[.1:.1:1];

%New scale is being started from 3. If we start from 1, 1 will be repeated
scale2=[3:2:9]; 

%Merging two variables scale1  and scale2
set(gca,'YTick',[scale1 scale2]);

Please refer http://www.mathworks.in/help/matlab/creating_plots/change-tick-marks-and-tick-labels-of-graph.html

Upvotes: 0

Benoit_11
Benoit_11

Reputation: 13945

There is an example by The Mathworks on Matlab answers which does pretty much what you want to achieve. The idea is to create 2 axes on the same figure and use one axes to plot some data (eg. for the 0.1:0.1:1 tick marks) and the rest on the other axes. Then you overlay both axes with a transparent background:

  %Create two overlapping axes
    axes_handle_1 = axes;
    axes_position = get(axes_handle_1, 'Position');
    axes_handle_2 = axes('Position', axes_position);

%Create some data with a large gap in the x domain
    my_x_data = [1:10 25:35];
    my_y_data = rand(1, length(my_x_data));
    %Plot the two sections of data on different axes objects
    plot(axes_handle_1, my_x_data(1:10), my_y_data(1:10))
    plot(axes_handle_2, my_x_data(11:end), my_y_data(11:end))

%Link the y axis limits and fontsize property of the axes objects
    linkaxes([axes_handle_1 axes_handle_2], 'y');
    linkprop([axes_handle_1 axes_handle_2], 'FontSize');
    %Set the x range limits and tick mark positions of the first axes object
    set(axes_handle_1, 'XLim', [1 21], ...
          'XTick', [1 5 10])

%Set the x range limits and tick mark positions for the second axes object.
    %Also set the background color to 'none', which makes the background
    %transparent.
    set(axes_handle_2, 'Color', 'none', ...
          'YTickLabel', [], ...
          'XLim', [14 35], ...
          'XTick', [25 30 35])

It's quite straightforward and to my knowledge there is no built-in way to do it otherwise, except maybe with submissions from the File Exchange. Anyhow if you have questions about the above code please ask!

Upvotes: 1

Related Questions