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.
0 个评论
采纳的回答
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!