Azzera filtri
Azzera filtri

How to change colormap based on z axis instead of y?

19 visualizzazioni (ultimi 30 giorni)
m=1;
%for m0=m=1
a=[0.636083933250372 0.212144382452125 0.0546892460944343 0.0811463126813785 0.0632774202126715 0.0562362171623843 0.0259131446756141 0.0354818222871739 0.0298812592457789 0.0257320939228473 0.0280840192189613 0.0154417739176394 0.0219552916746526 0.0195309258046508 0.0177406876770164 0.0170436180598679 0.0159776243553216 0.0151065623747937 0.0141630207464681 0.0120053692458791 0.0132297854767847 0.0105327350990362 0.0113560997799302 0.0110403184785192 0.0107906216617112 0.00965577268290680 0.00914800573096540 0.00939010508156453 0.00863569909353547 0.00811363665437132 0.00739932175763486 0.00782669890779222 0.00738448131419648 0.00719169948703580 0.00701385639284818 0.00596714585373073 0.00681989279886123 0.00639705878220211 0.00618647103207434 0.00600566361516922 0.00583327612646872 0.00223670709257374 0.00324888153217301 0.00177500910550813 0.00518658415713255 0.00488620011906528 0.00494929771417536 0.00474426340312584 0.00493698235122460 0.00484960741930230];
%for m0=0;
b=[0.00189556461205064 0.0456022928580212 0.0230374230583075 0.00465070019848336 0.00554094114694245 0.00215509807136384 0.00871713906558309 0.00387255244663482 0.00399544000350898 0.00435602086998625 0.00176873734569403 0.00501804904823206 0.00155464950684832 0.00164198976972907 0.00165198648715387 0.00157591055956975 0.00147253697899992 0.00152315325257481 0.00153689490345905 0.00200902938283806 0.00122463864364983 0.00192406567959340 0.00139704766840847 0.00131455885641305 0.00118818373143456 0.00135993322760032 0.00139859828103272 0.00115597327565545 0.00123220277279522 0.00126992289153737 0.00146233791862794 0.00117829401295292 0.00121975023758159 0.00119112277691794 0.00113525301230561 0.00138505108495600 0.000999986581559371 0.00107205149342070 0.00106211726981811 0.00102730498740808 0.000999241109613124 0.00135081047086154 0.00146659042839456 0.00118971057264901 0.000968334704691999 0.00101162244435133 0.000934737809385805 0.000959941768795119 0.000836451202409678 0.000829932259152043];
%for m0=2
c=[0.00189556461205064 0.0456022928580212 0.0230374230583075 0.00465070019848336 0.00554094114694245 0.00215509807136384 0.00871713906558309 0.00387255244663482 0.00399544000350898 0.00435602086998625 0.00176873734569403 0.00501804904823206 0.00155464950684832 0.00164198976972907 0.00165198648715387 0.00157591055956975 0.00147253697899992 0.00152315325257481 0.00153689490345905 0.00200902938283806 0.00122463864364983 0.00192406567959340 0.00139704766840847 0.00131455885641305 0.00118818373143456 0.00135993322760032 0.00139859828103272 0.00115597327565545 0.00123220277279522 0.00126992289153737 0.00146233791862794 0.00117829401295292 0.00121975023758159 0.00119112277691794 0.00113525301230561 0.00138505108495600 0.000999986581559371 0.00107205149342070 0.00106211726981811 0.00102730498740808 0.000999241109613124 0.00135081047086154 0.00146659042839456 0.00118971057264901 0.000968334704691999 0.00101162244435133 0.000934737809385805 0.000959941768795119 0.000836451202409678 0.000829932259152043];
y = [0 1 2];
z = [ b; a; c];
bar3(y,z);colorbar ;

Risposta accettata

Cris LaPierre
Cris LaPierre il 5 Giu 2023
a=[0.636083933250372 0.212144382452125 0.0546892460944343 0.0811463126813785 0.0632774202126715 0.0562362171623843 0.0259131446756141 0.0354818222871739 0.0298812592457789 0.0257320939228473 0.0280840192189613 0.0154417739176394 0.0219552916746526 0.0195309258046508 0.0177406876770164 0.0170436180598679 0.0159776243553216 0.0151065623747937 0.0141630207464681 0.0120053692458791 0.0132297854767847 0.0105327350990362 0.0113560997799302 0.0110403184785192 0.0107906216617112 0.00965577268290680 0.00914800573096540 0.00939010508156453 0.00863569909353547 0.00811363665437132 0.00739932175763486 0.00782669890779222 0.00738448131419648 0.00719169948703580 0.00701385639284818 0.00596714585373073 0.00681989279886123 0.00639705878220211 0.00618647103207434 0.00600566361516922 0.00583327612646872 0.00223670709257374 0.00324888153217301 0.00177500910550813 0.00518658415713255 0.00488620011906528 0.00494929771417536 0.00474426340312584 0.00493698235122460 0.00484960741930230];
b=[0.00189556461205064 0.0456022928580212 0.0230374230583075 0.00465070019848336 0.00554094114694245 0.00215509807136384 0.00871713906558309 0.00387255244663482 0.00399544000350898 0.00435602086998625 0.00176873734569403 0.00501804904823206 0.00155464950684832 0.00164198976972907 0.00165198648715387 0.00157591055956975 0.00147253697899992 0.00152315325257481 0.00153689490345905 0.00200902938283806 0.00122463864364983 0.00192406567959340 0.00139704766840847 0.00131455885641305 0.00118818373143456 0.00135993322760032 0.00139859828103272 0.00115597327565545 0.00123220277279522 0.00126992289153737 0.00146233791862794 0.00117829401295292 0.00121975023758159 0.00119112277691794 0.00113525301230561 0.00138505108495600 0.000999986581559371 0.00107205149342070 0.00106211726981811 0.00102730498740808 0.000999241109613124 0.00135081047086154 0.00146659042839456 0.00118971057264901 0.000968334704691999 0.00101162244435133 0.000934737809385805 0.000959941768795119 0.000836451202409678 0.000829932259152043];
c=[0.00189556461205064 0.0456022928580212 0.0230374230583075 0.00465070019848336 0.00554094114694245 0.00215509807136384 0.00871713906558309 0.00387255244663482 0.00399544000350898 0.00435602086998625 0.00176873734569403 0.00501804904823206 0.00155464950684832 0.00164198976972907 0.00165198648715387 0.00157591055956975 0.00147253697899992 0.00152315325257481 0.00153689490345905 0.00200902938283806 0.00122463864364983 0.00192406567959340 0.00139704766840847 0.00131455885641305 0.00118818373143456 0.00135993322760032 0.00139859828103272 0.00115597327565545 0.00123220277279522 0.00126992289153737 0.00146233791862794 0.00117829401295292 0.00121975023758159 0.00119112277691794 0.00113525301230561 0.00138505108495600 0.000999986581559371 0.00107205149342070 0.00106211726981811 0.00102730498740808 0.000999241109613124 0.00135081047086154 0.00146659042839456 0.00118971057264901 0.000968334704691999 0.00101162244435133 0.000934737809385805 0.000959941768795119 0.000836451202409678 0.000829932259152043];
y = [0 1 2];
z = [ b; a; c];
b = bar3(y,z);
colorbar ;
for k = 1:length(b)
zdata = b(k).ZData;
b(k).CData = zdata;
b(k).FaceColor = 'interp';
end
  2 Commenti
Athira T Das
Athira T Das il 5 Giu 2023
Modificato: Athira T Das il 5 Giu 2023
@Cris LaPierre Thank you! How can I label x, y, z axis in bar3? I need to change y axis values from (0 to 50 ) to (-25 to 25) and need to label as z
Cris LaPierre
Cris LaPierre il 5 Giu 2023
Modificato: Cris LaPierre il 5 Giu 2023
Labels are done using xlabel, ylabel, and zlabel,
Tick labels are similar: xticklabels, yticklabels, and zticklabels
Change the tick locations using: xticks, yticks, and zticks.

Accedi per commentare.

Più risposte (1)

Adam Danz
Adam Danz il 5 Giu 2023
This version assigns a solid color for each bar, based on bar height.
z = randg(1,5,3);
h = bar3(z);
for i = 1:numel(h)
h(i).CData = repelem(z(:,i),6,4);
end

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by