Zooming simultaneously in subplots [duplicate] - matlab

This question already has answers here:
MATLAB - How to zoom subplots together?
(3 answers)
Closed 7 years ago.
I created a figure with 8 subplots of timeseries objects, because I wanted to have an overview of the data.
Is there an option which gives me the following possibility:
If I zoom into one subplot (for example: just the range from 5 to 10 on the x-axis is now visible), than all other plots will automatically zoom in (such that the range from 5 to 10 on the x-axis is now just visible for all other subplots) too??

For linking both the x and y axes, you should use the command linkaxes. It takes as input a vector of handles to axis objects you want to link together, and additional options if desired.
Example:
for k = 1:4
ah(k) = subplot(2,2,k);
plot(1:10, rand(1,10));
end
linkaxes(ah);
After this, if you apply e.g. zooming on any of the subfigures, the x and y limits of the other axes will change as well.
If you want to link only, say, the x axis, use instead:
linkaxes(ah,'x');

Related

Adding XTickLabels to grouped individual bar graphs and plot on hold [duplicate]

This question already has answers here:
Getting a second row of xlabels in matlab graph?
(1 answer)
add data label to a grouped bar chart in matlab
(1 answer)
Closed 7 months ago.
I have two types of plots.
In fist case I need to label individual bar graphs in the grouped bar plot. Here is the example
a=4.54,88.63,27.27,77.27,54.54;31.81,61.36,38.63,68.18,54.54;54.54,61.36,59.09,54.54,50;68.18,27.27,56.81,34.09,50;90.90,11.36,68.18,15.90,40.90];
b=0.40,0.55,0.70,0.85,1;1.39,1.54,1.69,1.84,1.99;2.340,2.49,2.64,2.79,2.94;3.36,3.51,3.66,3.81,3.96;4.29,4.44,4.59,4.74,4.89];
figure,
hold on
for i=1:5
bar(b(i,:),a(:,i))
end
figure,
hold on
for i=1:3
plot(b(i,:),a(:,i))
end
For the bar plot, I like to lable on the horizontal as shown in figure, the numbers are stored in an other matrix, say b
2) Similarly, I also want to XTickLables using values in b for the line plot.
you have first to define xticks and XTickLables
for example you can write:
a=[....];
b=[....];
c=[0.5,1,1.5,2,3];
D = {'0.5','1','1.5','2','3'};
figure,
hold on
for i=1:5
bar(b(i,:),a(:,i));
xticks(i) = c(i); %% first you define the ticks
XTickLables{i} = d(i); %% second you define the labels
end
for the exact same plot like the one you showed, I think you need two nested for loops.
more on that here: https://de.mathworks.com/help/matlab/ref/xticklabels.html

How to plot with different colors [duplicate]

This question already has answers here:
How to hold a plot when using plot3 in matlab?
(1 answer)
plot hold for plot3 matlab
(1 answer)
Closed 5 years ago.
I am trying to plot a spiral with 8 turns. In each turn it is supposed to have a different color.
t = -1*pi*1:0.02:pi*1;
plot3(sin(t),cos(t),-1*pi*1:0.02:pi*1,'g')
t1 = -1*pi*2:0.02:pi*2;
plot3(sin(t1),cos(t1),-2*pi*1:0.02:pi*2,'r')
For now i am only plotting two turns, but it just turns out red. I have tried using hold on and hold off but its not working. Any suggestions?
check this
plot3(sin(t),cos(t),-1*pi*1:0.02:pi*1,'g-',sin(t1),cos(t1),-2*pi*1:0.02:pi*2,'r--')
The problem is that your red plot actually plots overtop of your previous one you should increase BOTH the lower bound and upper bound.
numberOfColors = 5;
for n = 0:numberOfColors-1
t = -pi + n*2*pi:0.02:pi + n*2*pi;
plot3(sin(t),cos(t),t,'Color',rand(3,1))
hold on
end

To reverse the values from up to down and change y-axis too in Matlab [duplicate]

This question already has answers here:
Turning y axis upside down in MATLAB
(5 answers)
Closed 9 years ago.
Example data:
I can change the values from up to down by the command
B(end:-1:1,:)
I run it and get
However, I want to change the values on the y-axis such that they go from 0 to 180.
How can you change the values on the y-axis in Matlab?
To change direction of y axis, including axis labels and plotted values, you use
set(gca,'YDir','reverse')
When you plot an image, for example using imagesc, the YDir property is automatically set to reverse. So, to change it, set it to normal:
set(gca,'YDir','normal')

MATLAB: How to change color of graph? [duplicate]

This question already has answers here:
Matlab Bar Graph - fill bars with different colours depending on sign and magnitude
(2 answers)
Closed 9 years ago.
This is the question I need to answer:
So far my function only reads:
function eval = plotupc(x)
bar(x, 'histc')
end
When I try to change the color of the graph, it stops my graph from being a histogram. Also, how can I make it so that my graph starts at 0 rather than 1?
The bar documentation states that
Note: You cannot specify names and values when using hist or histc options.
Instead, you can set the x-axis locations and bar width manually:
bar(0.5:numel(x)-0.5, x, 1, 'k');
axis tight;
The first argument gives the x locations of the bars; another example here. Here the bars are shifted one half to the right.
The second argument is of course your input.
The third argument specifies the width of the bars, a width of 1 ensures that they touch.
The last argument, 'k' is for key, i.e. black.
Finally, axis tight makes sure there is no leftover whitespace at the edges of the plot.
t=bar(0:1:length(x)-1,x,'histc');
set(t,'facecolor','k');
xlim([0 length(x)-1]);

Two left Y axis [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Plotting 4 curves in a single plot, with 3 y-axes
Dear stackoverflowers,
I need to plot 3 curves with same X axis (time) but three different dimensions (Volt, temp, current). The best outlook, to me, would be to have two Y axis on the left side, separated by a few pixel so we can read legend and ticks for each.
The answer to my questions are not plotyy neither multiple X or Y axis . In the first case, it helps me plot two different dimensions, not three.
the latter helps me associate right or left Y axis to a particular curve. I used the YAxisLocation option for my third curve but if I put it right or left, of course it interfers with the other YAxis that was there before. There is no option like left - 20 pixels ?
Thank you for your help.
You could just use plot (which will take care of the scale) and then include a legend to say what your units are (e.g. volts, degrees, etc)