Why the plot Limits are different if calling them differently?

1 次查看(过去 30 天)
On the image above you may see, that when calling the limit differently you have different result....Some month ago, it was OK... but now this issue make me crasy.
Many many thanks

回答(2 个)

Kishan Dhakan
Kishan Dhakan 2021-6-16
This looks related to display format. Could you try:
format longE
ax.YLim
This should show the same YLim as above in that image. This is happening because by default the display format in MATLAB is 'short'. You can get current display format by running:
fmt = format
  1 个评论
Sergii Snegir
Sergii Snegir 2021-6-16
Dear Kishan,
many thanks for your answer. It showed me one more time that something goes wrong with the code (the code is below).
I place below the code which used to work niicely before but after Matlab update and some of my moddifications it workds wrong.
At first I built the binscatter histogram and extract the position of limits, bins couns. Before this code exported data, for example the yLimit as [1.018591388054117E-6, 1.0011519555381663] now it exports as [0.0, 1.0005]. Your proposition to place fmt = format did not help. Do you have any other ideas?
Many thnska
% this is the working version of the software from May 2021
opengl software
clear all;
clear all;
format longE
clc;
% Sergii Snegir Version 2
%timestamps =["20210517150849","20210520085257"]
timestamps =["20210526132630"]
direc2find = 'opening'; %direction of the trace, opening or closing
state2find = 'off'; %state of the laser switched on or off
cond_lim=[1e-6 1]; % conductance data limits to extract the data set from the datafile
bend_lim=[-2 20];
fig_save="on";
save_mat="on";
file export properties
Imagformat='-dpng'; %format of exported images ('-djpeg' | '-dpng' | '-dtiff' | '-dpdf' | '-deps' | ...)
FonSize=12;
Data loading
datafile.dataset_full=[];
for i=1:length(timestamps)
filePathName= sprintf('..\\%s\\%s.mat',timestamps(1,i),timestamps(1,i))
datafileOne=load(filePathName);
datafile.dataset_full=[datafile.dataset_full; datafileOne.dataset_full];
end
clear datafileOne
Extracting data according to laser OFF or ON state, Opening or Closing
data_log=zeros(length(datafile.dataset_full),1);
for i = 1:length(datafile.dataset_full)
data_log(i,1)= datafile.dataset_full{i,1}.direction== direc2find & datafile.dataset_full{i,1}.state== state2find;
end
data_log= logical(data_log);
cleaned=datafile.dataset_full(data_log);
numTraces=length(cleaned);
Cutting the data range according to conductance limits
clear data_log
clear datafile
for i = 1:length(cleaned)
IDX=cleaned{i,1}.trace.conductance(:,1)<cond_lim(1,2) & cleaned{i,1}.trace.conductance(:,1)>cond_lim(1,1);
cleaned{i,1}.trace.conductance=cleaned{i,1}.trace.conductance(IDX);
cleaned{i,1}.trace.time=cleaned{i,1}.trace.time(IDX);
data_log(i,1)=any(round(cleaned{i,1}.trace.conductance,0)==1);% verify if the trace is correct trace (has 1G0 pont)
end
cleaned=cleaned(data_log);
Adjusting the position of G0
for i = 1:length(cleaned)
idx= find(round(cleaned{i,1}.trace.conductance,0)==1,1,'last'); %finding the index of the first row where G0=1
cleaned{i,1}.trace.time=seconds(cleaned{i,1}.trace.time-cleaned{i,1}.trace.time(idx,1));
end
Joining all data to one column, conductance and time respectvely
numTraces=length(cleaned);
fileNdata= split(cleaned{1,1}.filename,["..\","\","_","."]);
x=zeros(length(numTraces),1);
y=zeros(length(numTraces),1);
bend_idx=1000;
for i = 1:length(cleaned)
x=[x; (cleaned{i,1}.trace.time).*(0.01/60).*bend_idx]; % recalibrating time to bending (0.01mm/sec) and correcting mm to um in 1e-3 (*1000)
y=[y; cleaned{i,1}.trace.conductance];
end
%%cutting the data set from -2 to 20um (Bending limits) without this Bins count is wrong
clear idx
idx=(bend_lim(1,1)<x) & (x<bend_lim(1,2));
x=x(idx);
y=y(idx);
clear idx
%%ploting the data
h=binscatter(x,y,250,'FaceAlpha',1);
h.ShowEmptyBins = 'off';
ax = gca;
ax.YScale="log";
ax.XLim=([-2 20]);
ax.YLim=(cond_lim);
x_lim=h.XLimits;
y_lim=h.YLimits;
counts=h.Values;
xbin=h.XBinEdges;
ybin=h.YBinEdges;
% exportPath2_cont=sprintf('figures\\contours\\%s_from_2D-histo',timestamps(1,1));
% save(sprintf('%s_counts.mat',exportPath2_cont), 'counts','timestamps','xbin','ybin','x_lim','y_lim');
%
map_pos=[0 .05 .1 .15 .44 .68 1];
ax.Color=[0 0 0];
map = customcolormap(map_pos, {'#000000','#36596a', '#007fff','#00FF0F','#F4FF00','#FF9F00','#FF0D00'}); %blau Rot ;
%-------
colormap (ax, flipud(map));
c=colorbar;
c.LineWidth=1.2;
c.FontSize=FonSize;
%%Transformation of the colorbar
maxLim_value=c.Limits(1,2);
start_point = 0.4; % 40% of the colorbar: This is a new starting point of the color bar
c.Limits=[0 c.Limits(1,2)*start_point]; % we show 40% of the colorbar
[~,tsN]=size(c.Ticks); %define the number of tickes presented
new_ticks= round(linspace(0,start_point,tsN),2,'significant'); % generating a new tickes wit the same number in old graph starting from a new starting point
c.TickLabels=new_ticks;
c.Label.String="Bins count (A.U.)"
%%Decoration of the graph
ax.YAxis.TickValues =[1e-6 1e-5 1e-4 1e-3 1e-2 1e-1 1];
ax.YGrid = 'on';
ax.XGrid = 'on';
ax.LineWidth = 1.5;
ax.XAxis.Label.String ="Bending (\mum)";
ax.YAxis.Label.String ="Conductance (G_0)";
ax.YScale="log";
ax.FontSize = FonSize;
ax.Layer = 'top';
ax.GridLineStyle = '-';
ax.GridColor='w';
ax.LineWidth = 1;
ax.YMinorGrid = 'off';
ax.Box='on';
leg_prop = line(nan, nan, 'Linestyle', 'none', 'Marker', 'none', 'Color', 'none');
infor=sprintf('traces %s\n%s',num2str(numTraces),strjoin(timestamps,'\n')); % simple information to the legend
lg=legend(leg_prop,infor);
lg.Box='off';
lg.TextColor='white';
%%data to matfile
% save(sprintf('figures\\contours\\%s_from_2D-histo_counts.mat',timestamps(1,1)),'counts', 'timestamps','x_lim','y_lim','xbin','ybin')
exportPath2_cont=sprintf('figures\\contours\\%s_from_2D-histo',timestamps(1,1));
save(sprintf('%s_counts.mat',exportPath2_cont), 'counts','timestamps','xbin','ybin','x_lim','y_lim');

请先登录,再进行评论。


Sergii Snegir
Sergii Snegir 2021-6-18

类别

Help CenterFile Exchange 中查找有关 Orange 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by