The scale of the x-axis (Format: HH:MM:SS)
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ramo Rafsel
le 10 Août 2020
Modifié(e) : Ramo Rafsel
le 18 Août 2020
I have 2 imported columns from excel that I plotted already, the time column ( the format HH:MM:SS) is on the x-axis and the value column is on the y-axis.
The problem that I am trying to solve since both the columns are 1645 long (or better said: they contain 1645 rows), so I want to change the x axis scale on the graph to make the distance between the times somehow longer, otherwise it looks like a long unwanted line under the x-axis.
Any Ideas how to change the x-axis scale on the graph for a better appearance?
The second hurdle that I am facing, I keep getting the error below whenever I try to plot the average line of the value column on the same graph where the time and the value column are plotted. Maybe because the x and y axis are already used?
avgline= sum(value_column)/size(value_column),1); %the value_column and time column are already defined from the workspace)
nexttile
plot(time_column,value_column)
hold on
plot(avgline,'-r','LineWidth',2);
title('Value 6')
hold off
%The Error that I get:
%Values plotted against x-axis must be categorical values. To create categorical values, use the categorical function.
0 commentaires
Réponse acceptée
Shae Morgan
le 10 Août 2020
Modifié(e) : Shae Morgan
le 10 Août 2020
try looking into the 'xtick' property to specify which x-ticks you want to show. it'll suppress the rest of them
x=1:10; %demo time values
y=1:10; %demo data
plot(x,y) %create figure
set(gca,'xtick',[1 3 6 10]) %manipulate x-axis to only show some values
10 commentaires
Shae Morgan
le 14 Août 2020
you don't have to make up random data to use for your y-axis. Just use the variable you have. You didn't provide any of your data, so I had to make-up numbers for the y and x axes to demonstrate the fix for the x-axis. You substitute those lines of code for what you already have and it should work.
%You don't need this code if you already have a time5 and v5 variable
%I added this code in order to demonstrate the fix
t1 = datetime(2020,8,12,13,11,24); %start time
t2 = datetime(2020,8,12,13,18,36); %end time
time5 = t1:seconds:t2; %create a vector of time points from the start time to the end time
v5 = randn(size(time5)); %create random y-axis data
% --------------^^^^^----- don't use this code if you already have your time5 and v5 variables!
%end set-up section
%use this code with your original time5 and v5 data that you already have stored as variables
plot(time5,v5) %plot data
hold on; %hold the current figure so the first plot doesn't erase when you do the 2nd plot
avg5 = mean(v5); %the average value of v5
x2= [time5(1) time5(end)]; %x-values for the average line
plot(x2,[avg5 avg5], 'y-', 'LineWidth',2); %plot the avg line
title('value 5 by time plot') %title the plot
legend('Raw data','Average line') %add a legend to differentiate the two data sources
ax = gca; %get current axis
x_step_size=100; %step size between labels in seconds
ax.XAxis.TickValues = t1:seconds(x_step_size):t2; %adjust the tick values to the correct spacing
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Visual Exploration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!