How to manage weird black line on Y axis outside the figure itself
    2 次查看(过去 30 天)
  
       显示 更早的评论
    
Hello,
I'm struggulling with some of my plot because some of my data looks squished together out of the box. 
I'm working with data from a wheater station who give me a text file with csv separation to treat the data (See attachments).  I used an automatic import who is working perfecly for others stations. I have the same trouble with another station but most of them get good result. 
Below are the figure with the red circle to show the weird part and the code to get there : 

%% Import data from text file
% Auto import for txt file from Idaweb
clear all;
close all;
% Script for importing data from the following text file:
%
%    filename: C:\Users\Brian\Documents\Etude\Master\Cours\These_Master\Data\Idaweb\Diableret\Diableret_1900_data.txt
%
% Auto-generated by MATLAB on 18-Nov-2022 14:30:37
%% Set up the Import Options and import the data
opts = delimitedTextImportOptions("NumVariables", 8);
% Specify range and delimiter
opts.DataLines = [4, Inf];
opts.Delimiter = ";";
% Specify column names and types
opts.VariableNames = ["Var1", "time", "gre000h0", "prestah0", "tre200h0", "ure200h0", "fkl010h0", "dkl010h0"];
opts.SelectedVariableNames = ["time", "gre000h0", "prestah0", "tre200h0", "ure200h0", "fkl010h0", "dkl010h0"];
opts.VariableTypes = ["string", "char", "categorical", "categorical", "categorical", "categorical", "categorical", "categorical"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
% Specify variable properties
opts = setvaropts(opts, "Var1", "WhitespaceRule", "preserve");
opts = setvaropts(opts, ["Var1", "gre000h0", "prestah0", "tre200h0", "ure200h0", "fkl010h0", "dkl010h0"], "EmptyFieldRule", "auto");
% Import the data
Diableret1900data = readtable("C:\Users\Brian\Documents\Etude\Master\Cours\These_Master\Data\Idaweb\Diableret\Diableret_1900_data.txt", opts);
%% Clear temporary variables
clear opts
% Make a time vector to display the date 
Cell_Diabl_data = table2cell(Diableret1900data);
Time_vector_Diabl_data = datetime(Cell_Diabl_data(:,1),"InputFormat","yyyyMMddHH");
TT_Diabl_data = table2timetable(Diableret1900data,"RowTimes",Time_vector_Diabl_data);
plot(TT_Diabl_data.Time(1:height(Diableret1900data)),TT_Diabl_data.tre200h0(1:height(Diableret1900data)))
title('Temperature area')
ylabel('température [°C ]')
xlabel('Time')
0 个评论
采纳的回答
  Star Strider
      
      
 2022-11-19
        I cannot reproduce what you’re seeing.  
I don’t understand the temperature data after about 2013 (I have no idea what the dense blue area represents), however the rest of it plots normally.  
Try something like this — 
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1199568/Diableret_1900_data.zip')
Diableret1900data = readtable(Uz{1});
Diableret1900data.time = datetime(string(Diableret1900data{:,2}),"InputFormat","yyyyMMddHH")
figure
plot(Diableret1900data.time, str2double(Diableret1900data.tre200h0))
title('Temperature area')
ylabel('température [°C ]')
xlabel('Time')
[Utime,Uix] = unique(Diableret1900data.time);
figure
plot(Diableret1900data.time(Uix), str2double(Diableret1900data.tre200h0(Uix)))
title('Temperature area (Unique Dates & Times)')
ylabel('température [°C ]')
xlabel('Time')
% Lv = isbetween(Diableret1900data.time, "2015-01-01", "2015-01-02");
% Excerpt = Diableret1900data(Lv,:)
See the documentation on str2double, since I get the impression from your posted code that you’re not actually converting it.  
The strange results from about 2013 onward appear to result in the dates not all being unique.  When I found the unique times (the first instance of every specific time, see the documentation on unique for details), the anomalous temperatures largely disappeared.  I was simply curious to see if I could determine what the problem was, and duplicated dates with aberrant temperature values appear to be the reason.  I leave that to you to explore (and correct if necessary).  
.
2 个评论
  Star Strider
      
      
 2022-11-21
				As always, my pleasure!  
The ‘black line’ were the y-tick labels.  I forgot to mention that initially.  
.
更多回答(0 个)
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



