How to manage weird black line on Y axis outside the figure itself

1 view (last 30 days)
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.
I also see that I wasn't the only one to struggle with those black line but that did'nt help me
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')

Accepted Answer

Star Strider
Star Strider on 19 Nov 2022
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')
Uz = 1×1 cell array
{'Diableret_1900_data.txt'}
Diableret1900data = readtable(Uz{1});
Diableret1900data.time = datetime(string(Diableret1900data{:,2}),"InputFormat","yyyyMMddHH")
Diableret1900data = 349662×8 table
stn time gre000h0 prestah0 tre200h0 ure200h0 fkl010h0 dkl010h0 _______ ____________________ ________ ________ ________ ________ __________ ________ {'DIA'} 09-Oct-1992 08:00:00 {'-'} {'-'} {'-' } {'-'} {'-' } {'-'} {'DIA'} 09-Oct-1992 09:00:00 {'-'} {'-'} {'-' } {'-'} {'975.4' } {'-'} {'DIA'} 09-Oct-1992 10:00:00 {'-'} {'-'} {'2.7'} {'-'} {'1003.9'} {'-'} {'DIA'} 09-Oct-1992 11:00:00 {'-'} {'-'} {'3.4'} {'-'} {'858.9' } {'-'} {'DIA'} 09-Oct-1992 12:00:00 {'-'} {'-'} {'3.8'} {'-'} {'783.1' } {'-'} {'DIA'} 09-Oct-1992 13:00:00 {'-'} {'-'} {'3.2'} {'-'} {'775.9' } {'-'} {'DIA'} 09-Oct-1992 14:00:00 {'-'} {'-'} {'3.3'} {'-'} {'562.6' } {'-'} {'DIA'} 09-Oct-1992 15:00:00 {'-'} {'-'} {'2.7'} {'-'} {'-' } {'-'} {'DIA'} 09-Oct-1992 16:00:00 {'-'} {'-'} {'2.3'} {'-'} {'-' } {'-'} {'DIA'} 09-Oct-1992 17:00:00 {'-'} {'-'} {'1.6'} {'-'} {'373.8' } {'-'} {'DIA'} 09-Oct-1992 18:00:00 {'-'} {'-'} {'1.3'} {'-'} {'643.3' } {'-'} {'DIA'} 09-Oct-1992 19:00:00 {'-'} {'-'} {'1.0'} {'-'} {'797.7' } {'-'} {'DIA'} 09-Oct-1992 20:00:00 {'-'} {'-'} {'1.0'} {'-'} {'560.0' } {'-'} {'DIA'} 09-Oct-1992 21:00:00 {'-'} {'-'} {'0.5'} {'-'} {'455.1' } {'-'} {'DIA'} 09-Oct-1992 22:00:00 {'-'} {'-'} {'0.3'} {'-'} {'429.4' } {'-'} {'DIA'} 09-Oct-1992 23:00:00 {'-'} {'-'} {'0.4'} {'-'} {'458.5' } {'-'}
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 Comments
Star Strider
Star Strider on 21 Nov 2022
As always, my pleasure!
The ‘black line’ were the y-tick labels. I forgot to mention that initially.
.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!