how to plot y double right axis linear graph?

1 vue (au cours des 30 derniers jours)
SOMNATH MAHATO
SOMNATH MAHATO le 10 Mai 2022
x = [162 132 190 470 187 157 215 495 165 135 193 473 302 272 330 610 942 912 970 1250];
y1 = [1.21 0.491; 0.938 0.388; 0.237 0.159; 0.379 0.158; 0.45 0.182; 0.43 0.179; 0.382 0.091; 0.433 0.177; 0.933 0.34; 0.261 0.244; 0.092 0.038; 0.0406 0.016; 0.357 0.156; 0.193 0.101; 0.097 0.063; 0.0972 0.0371; 0.259 0.139; 0.176 0.072; 0.076 0.031; 0.0777 0.0324];
y2 = [21.7 50.89 57.86 45.62 3.62 35.03 36.72 45.52 48.37 54.29 70.18 66.63 64.32 65.18 77.83 98.25 67.49 70.4 35.34 99.2];
figure('Color','w')
[hAx,hLine1,hLine2] = plotyy(x,y1,x,y2);
xlabel ('cost(USD)')
ylabel(hAx(1),'value (m)') % left y-axis
ylabel(hAx(2),'solution Percentage (%)') % right y-axis
grid on
Y2axis right
ax.Ylable(hAx(2)).Color = 'r';

Réponse acceptée

Prakash S R
Prakash S R le 10 Mai 2022
What exactly is the problem? I'm guessing that you are bothered by the fact that the line connecting the points is all squiggly, because the x points are not in increasing order. Maybe if you sorted x and replotted, you'll find a more meaningful plot:
[sx, inds] = sort(x);
[hAx,hLine1,hLine2] = plotyy(sx,y1(inds),sx,y2(inds));

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by