How to use Xlim which refer to one x-axis in yyaxis function?

Hi! I have a question about how to use xlim in yyaxis function which refer to one x-axis. I have two types of chart in one figure. They both have different x-axis and y-axis. One y-axis has a reversed value and I want its x-axis value refer to the other one. I try to find the example in mathworks question but I could not find it. Could you please help me? Here is the code I wrote:
%%Plot Flow [l/min] and Cumulative Rainfall Depth [mm] (Figure 3)
x1=flowCSV{:,'DateAndTime'};
x2=rainanalysis{:,'DatumUhrzeit'};
y1=flowCSV{:,'Durchflusslm'};
z1=flowCSV{:,'SmoothedFlow'};
y2=rainanalysis{:,'CumulativeRainfallDepth'};
figure(3);
ax=gca;
yyaxis left
plot(x1,y1,'-b',x1,z1,'-g');
xlabel('Date and Time');
ylabel('Flow [l/min]');
yyaxis right
bar(x2,y2,'r');
ax.YDir = 'reverse';
title('Flow and Rainfall');
ylabel('Rainfall [mm]');
grid on % show grid on plot
datacursormode on % enable to display data value interactively in the plot
clearvars ax x* y* z* % clear temporary variables

Antworten (1)

Birdman
Birdman am 26 Nov. 2017
You should write the necessary code under that figure definiton for x axis as follows:
set(gca,'XLim',[0 10]);%the limits are random

3 Kommentare

Thanks for your reply. I know we have to use xlim for this purpose and it is easier if we can determine the value like 1 to 10. I mean I want to use x2 for "yyaxis right" which has the same value as x1, so it should refer to x1. Do you know how to do it? Thank you in advance
What do you mean by refer? Be more specific.
For example, x1 ranges from 01 November until 15 November, x2 ranges from 10 November until 23 November. I want y2 value here shown based on x1, so the data shown in figure for y2 should be from 10 November until 15 November (intersection). Therefore in my figure x-axis is x1 value. In my code above, x-axis value is the combination of both x1 and x2. I want to use Xlim for this purpose but I do not know how to do it.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Axes Appearance finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by