Problem with color plotting 2d array in a multiple y plot of axes with a 1d array

조회 수: 2 (최근 30일)
So I have to plot a yyplot in an axes. There are 3 arrays one for time called BatteryNewTimeSection, one for CellVoltages called allCellVoltageForPressurePlot and one called newPressure for pressure. Pressure and cellvoltages are the 2 y axis and time is the x axis. Cell voltage is a 2d array and time and pressure are 1d arrays. Now the problem is cell voltages. There are 84 cell voltages and when I plot them they are all coming in the same colour. Here is the code below :
lx = axes;
yyaxis(lx,'left');
plot(lx,BatteryNewTimeSection,allCellVoltageForPressurePlot);
yyaxis(lx,'right');
plot(lx,BatteryNewTimeSection,newPressure);
and here is the plot
As you can see all the cell voltages appear as one colour.
I tried plotting it single y without the pressure and there it works. here is the code :
lx = axes;
plot(lx,BatteryNewTimeSection,allCellVoltageForPressurePlot);
and here is the plot :
So why is this happening, the top is all colour and bottom is correct with multi color cell voltages and how can I correct this.I have also uploaded the three arrays as .mat file. Thank you.

채택된 답변

Cris LaPierre
Cris LaPierre 2025년 6월 12일
The lines in a YYaxis plot are designed to have the same color as their cooresponding Y axis (blue for the left, orange for the right). My assumption is that this was to make it easier to know what axis to compare the line to.
load batfile.mat
lx = axes;
yyaxis(lx,'left');
plot(lx,BatteryNewTimeSection,allCellVoltageForPressurePlot);
yyaxis(lx,'right');
plot(lx,BatteryNewTimeSection,newPressure);
The colors used to plot subsequent series comes from the colororder property. You can reset this for the left axis if you want to restore the default colors.
figure
lx = axes;
yyaxis(lx,'left');
colororder('gem')
plot(lx,BatteryNewTimeSection,allCellVoltageForPressurePlot);
yyaxis(lx,'right');
plot(lx,BatteryNewTimeSection,newPressure);
Warning: Hardware-accelerated graphics is unavailable. Displaying fewer markers to preserve interactivity.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by