Filter löschen
Filter löschen

How can I plot a matrix using pcolor and colorscale as log?

43 Ansichten (letzte 30 Tage)
AMIT SINGH CHANDEL
AMIT SINGH CHANDEL am 16 Jul. 2024 um 11:33
Kommentiert: Star Strider am 17 Jul. 2024 um 13:39
I have a timeseries matrix data of a lidar. I want to plot the time series keeping colorbar as logscale.
I have written the following code but it shows an error
load time_June.mat
load elevation_June_5km.mat
load backscatter_June_5km.mat
load raw_backscatter_June_5km.mat
figure(1);
pcolor(time_June, elevation_June_5km, backscatter_June_5km); shading interp
c = colorbar;
caxis([10^-7 10^-4]);
set(gca, 'ColorScale', 'log');
c.Label.String = 'Attenuated backscatter coefficient (m^{-1} sr^{-1})';
c.Ruler.Scale = 'log';
c.Ruler.MinorTick = 'on';
colormap jet;
set(gca, 'YDir', 'normal');
xlabel('Time (LT)');
ylabel('Altitude (km)');
axis tight;
set(gca, 'FontName', 'Times', 'FontSize', 14);
startDate = datetime(2023, 6, 16);
endDate = datetime(2023, 6, 25);
xlim([startDate, endDate]);
Error:
Warning: Error creating or updating Surface
Error in value of property CData
DataSpace or ColorSpace transform method failed.
  2 Kommentare
Sahas
Sahas am 17 Jul. 2024 um 7:47
Verschoben: Star Strider am 17 Jul. 2024 um 10:14
I've taken a look at the code and ran a few simlations with dummy data. But to generate the given errors, it would requires the specific files to load the workspace variables. Could you please share those files so that I could further investigate for the cause of this behaviour?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 16 Jul. 2024 um 11:55
According to the ColorScale documentation, that property should set the colorbar scale as well.
I would not use pcolor. The best option would likely be to use surf and view, spedifically view(2).
  3 Kommentare
Star Strider
Star Strider am 16 Jul. 2024 um 13:04
I cannot figure out what you are doing. I also do not have your data, so I cannot experiment with it.
Using an example from Specify True Colors for Surface Plot and adding a ColorScale call, I get this result —
[X,Y,Z] = peaks(25);
CO(:,:,1) = zeros(25); % red
CO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % green
CO(:,:,3) = ones(25).*linspace(0,1,25); % blue
figure
surf(X,Y,Z,CO)
Ax = gca;
Ax.ColorScale = 'log';
colorbar
.
Star Strider
Star Strider am 17 Jul. 2024 um 13:39
It works in R2024a without error,so perhaps an upgrade would be appropriate.
Note that your desired dates (at least for this data set) are not included in the ‘time_June’ datetime array.
files = dir('*.mat');
NrFiles = numel(files)
NrFiles = 3
for k = 1:numel(files)
filename = files(k).name
vars = whos('-file', filename);
varname = vars.name;
load(filename)
Sz = vars.size
end
filename = 'backscatter_June_5km.mat'
Sz = 1x2
500 5760
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
filename = 'elevation_June_5km.mat'
Sz = 1x2
500 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
filename = 'time_June.mat'
Sz = []
figure(1)
% surf(backscatter_June_5km, 'EdgeColor','interp')
surf(time_June, elevation_June_5km, backscatter_June_5km, 'EdgeColor','interp')
c = colorbar;
caxis([10^-7 10^-4]);
set(gca, 'ColorScale', 'log');
c.Label.String = 'Attenuated backscatter coefficient (m^{-1} sr^{-1})';
c.Ruler.Scale = 'log';
c.Ruler.MinorTick = 'on';
colormap jet;
set(gca, 'YDir', 'normal');
xlabel('Time (LT)');
ylabel('Altitude (km)');
axis tight;
set(gca, 'FontName', 'Times', 'FontSize', 14);
startDate = datetime(2023, 6, 16);
endDate = datetime(2023, 6, 25);
CheckDates = nnz(ismember(time_June, [startDate, endDate]))
CheckDates = 0
time_June_Range = [min(time_June); max(time_June)]
time_June_Range = 2x1 datetime array
01-Jun-2023 00:00:00 02-Jun-2023 23:59:30
% xlim([startDate, endDate]);
.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by