Contour Plot Wrong Colors

5 views (last 30 days)
Alberto Mateos Bond
Alberto Mateos Bond on 13 Aug 2022
Edited: Star Strider on 14 Aug 2022
Hi guys,
I have made a contourf interpolating results with meshgrid and it plots a graph which does not correspond to the values that I put as input with the colors of the colorbar (There are points where it should be yellow or red and it is blue, or other points which have markedly different values and are the same color). I don't know if it's a problem with the interpolation method, I think not since I've checked that and the numbers are consistent. I don't see a problem with the contour either. I don't know if I should use another interpolation method and I dont unterstand what exactly is wrong.
clear all;clc;
A=[77.3139227401096,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.8499350764564,77.8442382759329,77.8400158037560,77.8367460305253,77.8341382601430,77.3189088790396,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.4228460196533,77.3770975908979,77.3678714954335,77.3624256179988,77.3588314539844,77.3562741687948,77.3543880471537,77.3529118848689,77.3517359358068,77.8230143346564,77.5947167588728,77.4572289300964,77.3536200322737,77.2815354478640,77.1958950775090,77.1462000726089,77.1176650859710,77.1045877194747,77.0939198939992,77.0960045406636,77.0936701640036,77.0918470331206,77.0903910018129,78.9250781251261,78.2607772080247,77.8571819100295,77.5445345646900,77.1777675777582,77.1067936547286,77.0560757369439,77.0204796252278,77.0021470133600,76.9934357792392,76.9874018876342,76.9841903129164,76.9834146935698,76.9832804850934];
torque=[-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100,-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100,-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100,-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100];
rpmrange=[6,6,6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,8,8,8,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5];
[xmesh,ymesh]=meshgrid(torque,rpmrange);
vq=griddata(torque,rpmrange,A,xmesh,ymesh);
contourf(xmesh,ymesh,vq,1000,'EdgeColor','none')
xlabel('Torque increase [%]');
ylabel('RPM range [*10^3]');
title('Torque Sensivity Study');
hc = colorbar;
set(get(hc,'title'),'string','LapTime [s]')
colormap(flipud(jet))

Answers (1)

Star Strider
Star Strider on 14 Aug 2022
Edited: Star Strider on 14 Aug 2022
I get a slightly different result when I use ‘torquev’ and ‘rpmrangev’ to define the interpolation grids, so that may be the problem, since ‘torque’ and ‘rpmrange’ are themselves actually (14x4) matrices. My change uses their ranges to define the interpolation matrices.
I also ploted the result based on the original reshaped matrices in the second figure.
Try this —
A=[77.3139227401096,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.8499350764564,77.8442382759329,77.8400158037560,77.8367460305253,77.8341382601430,77.3189088790396,77.3120257063849,77.3120257063849,77.3120257063849,77.3120257063849,77.4228460196533,77.3770975908979,77.3678714954335,77.3624256179988,77.3588314539844,77.3562741687948,77.3543880471537,77.3529118848689,77.3517359358068,77.8230143346564,77.5947167588728,77.4572289300964,77.3536200322737,77.2815354478640,77.1958950775090,77.1462000726089,77.1176650859710,77.1045877194747,77.0939198939992,77.0960045406636,77.0936701640036,77.0918470331206,77.0903910018129,78.9250781251261,78.2607772080247,77.8571819100295,77.5445345646900,77.1777675777582,77.1067936547286,77.0560757369439,77.0204796252278,77.0021470133600,76.9934357792392,76.9874018876342,76.9841903129164,76.9834146935698,76.9832804850934];
torque=[-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100,-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100,-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100,-40,-30,-20,-10,10,20,30,40,50,60,70,80,90,100];
rpmrange=[6,6,6,6,6,6,6,6,6,6,6,6,6,6,8,8,8,8,8,8,8,8,8,8,8,8,8,8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5,12.5];
torquev = linspace(min(torque), max(torque), numel(torque));
rpmrangev = linspace(min(rpmrange), max(rpmrange), numel(rpmrange));
[xmesh,ymesh]=meshgrid(torquev,rpmrangev);
vq=griddata(torque,rpmrange,A,xmesh,ymesh);
figure
contourf(xmesh,ymesh,vq,1000,'EdgeColor','none')
xlabel('Torque increase [%]');
ylabel('RPM range [*10^3]');
title('Torque Sensivity Study');
hc = colorbar;
set(get(hc,'title'),'string','LapTime [s]')
colormap(flipud(jet))
torque_mtx = reshape(torque,14,[])
torque_mtx = 14×4
-40 -40 -40 -40 -30 -30 -30 -30 -20 -20 -20 -20 -10 -10 -10 -10 10 10 10 10 20 20 20 20 30 30 30 30 40 40 40 40 50 50 50 50 60 60 60 60
rpmrange_mtx = reshape(rpmrange,14,[])
rpmrange_mtx = 14×4
6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000 6.0000 8.0000 10.0000 12.5000
A_mtx = reshape(A,14,{})
A_mtx = 14×4
77.3139 77.3189 77.8230 78.9251 77.3120 77.3120 77.5947 78.2608 77.3120 77.3120 77.4572 77.8572 77.3120 77.3120 77.3536 77.5445 77.3120 77.3120 77.2815 77.1778 77.3120 77.4228 77.1959 77.1068 77.3120 77.3771 77.1462 77.0561 77.3120 77.3679 77.1177 77.0205 77.3120 77.3624 77.1046 77.0021 77.8499 77.3588 77.0939 76.9934
figure
contourf(torque_mtx,rpmrange_mtx,A_mtx,1000,'EdgeColor','none')
xlabel('Torque increase [%]');
ylabel('RPM range [*10^3]');
title('Torque Sensivity Study (Original Matrices)');
hc = colorbar;
set(get(hc,'title'),'string','LapTime [s]')
colormap(flipud(jet))
EDIT — (14 Aug 2022 at 13:14)
This might be easier to appreciate with a surfc plot —
figure
surfc(torque_mtx,rpmrange_mtx,A_mtx)
% shading('interp')
% hold on
% contour3(torque_mtx,rpmrange_mtx,A_mtx,50,'-k')
% hold off
xlabel('Torque increase [%]');
ylabel('RPM range [*10^3]');
title('Torque Sensivity Study (Original Matrices)');
hc = colorbar;
set(get(hc,'title'),'string','LapTime [s]')
colormap(flipud(jet))
grid on
view(35,20)
.

Community Treasure Hunt

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

Start Hunting!