how to put the different times in y axis in matlab - excel

greeting for every one,
I have data in excel file and i want to draw a plot in Matlab in which the Y axis represent the time with starting time in 10:45 for 24 hours i.e, from 10:00 am to the next day in 10:00 am. The x-axis represents the excel file data( the values of frequencies during 24 hours)
how to put the different times in the y axis showing the values of time in the formula of time(00:00 am/pm) using matlab?
if i use this code: ylim(subplot2,[1 24]) and xlim(subplot2,[170 230]) it will be plotted but the y-axis shows only the hours from 1 to 24 hours and i need the y-axis from 10:45 am(starting time) to(10:45)am in interval 24 hours

You can create custom tick labels by specifying tick strings with the command:
time_cells = {'10:45','11:45',...,'9:45','10:45'};
set(gca, 'YTickLabel', time_cells)
Where gca is the handle of your current plot (axes), and the time_cells is a cell array containing all your required tick labels (without the ellipse). It is probably easiest to generate this using a for-loop to create the numbers you want, and then num2str to convert to the strings you need.

Related

create stacked column chart to show running time

I have data on 5 runners for 1 week; start time and end time in a race. I want to graph how long it took each runner to finish the race
when I subtract the cells for start and end time, I get a result as 3:00 AM instead of 3 hours. I think this is why I'm having an issue creating a stacked column chart
how can I subtract 2 timestamps and get it to spit out just the hours instead of another time stamp?
I want the date on x axis and time to complete the race on y axis
thank you
here is a sample of the data
https://imgur.com/xRyDynl
i want a stacked column chart that has dates on the x axis. so 1/1 will have 1 bar that has 30 mins for racer 1, 35mins for 2, and 40 mins for 3

Specifying the number of ticks in between a range

I have written code for customizing my x ticks, snippet of the same is below
arr_label = ['sum_msg_len','log_count','info_hit','debug_hit','error_hit']
for label in arr_label :
fig = plt.figure(figsize=(15,6))
axes = fig.add_axes([1,1,1,1])
axes.xaxis.set_major_locator(plt.LinearLocator(30))
axes.tick_params(axis ='x',labelsize=6)
axes.plot(df.index,df[label],'g',label =label)
axes.legend()
fig.autofmt_xdate()
fig.savefig('images_indv/'+app_index+"_"+label+".png",bbox_inches='tight')
#fig.close()
fig.clf()
my requirement is that is have timestamps spaced by minute and i want to plot timestamp vs ('sum_msg_len'/'log_count'/'info_hit'/'debug_hit'/'error_hit') one by one,
but problem is X ticks, i want some specified no of ticks to appear within the range of the data which i am plotting.
Earlier when i was not specifing any Locator then all the timestamps got overlapped and one cannot read the timestamps properly. So when i try to use a locator, it labels the x-axis with out any relation to the plotted value.
Like if i use LinearLocator(30) it just plots the first 00 to 29 mins in the graph,and if i use LinearLocator(50) it just plots the first 00 to 49 mins in the graph with no change to the y axis values. Plots of both I am putting below. I also tried with different locators Like MultipleLocator and MaxNlocator, but issue sustains
In short, I just want the graph plotted for 21July 00:00:00 to 22 July 00:00:00 which will be 1440 entries but the i want to see around 30-40 intermediate entries mentioned on the plot.

Plotting time on X axis in excel

I have done 24 hour measurement and results obtain contains around 1400 entries. Now I want to plot those results in such a way
That x axis represent my time and y axis the corresponding value.
My x axis should be divided into 24 sections each representing 1
hour.
My exact start time is 14:00 and end time is next day 14:00.
For more clarification I am adding a simple version of my data here below
And resulting Plot I am getting is this.
I look forward to your answers. Thank you.
If the time values go across midnight, you need to add a date part to the time value, so they can be plotted correctly as before and after midnight. At the very least, the time values for the first day should have a 0 before the decimal, e.g. 0.875 for 9 pm, and the values after midnight should have a 1 before the decimal, e.g. 1.125 for 1 am, so it falls on the next day and not the same day as the 9pm value.
Then plot an XY Scatter chart.
Work out what Excel's internal number (date/time value showing in General format) is for the desired X axis minimum, maximum and major/minor increments and format the x axis accordingly. Set the number format to hh:mm
Edit: For example: you want the minimum X axis value to be 24-Dec-2015 11 pm. Write that into a cell as a date/time. Format the cell to General. Then use the number you see in the format dialog for the X axis minimum.
If you want the major unit to be 1 hour, write the time value 1:00 into a cell and format it with general. Use that number in the dialog for Major.
Format the X axis labels to show time values, not dates.

Labeling axis. Convertion from Excel. Convert data into String

How would you plot an A vs B graph,where A and B are columns in Excel such as
A
Red
Green
Blue
and
B
1:00 AM
2:00 AM
3:00 AM
for 3*3 graphs I use
set(gca,'XTick',1:3);
set(gca,'XTickLabel',{'Red','Green','Blue'});
set(gca,'YTick',1:3);
set(gca,'YTickLabel',{'1:00 AM','2:00 AM','3:00 AM'});
However manual entering for 1000*1000 would be a mess.
So my question is:
How do I convert values Red Green Blue from column A as {'Red','Green','Blue'}? (in order to use them in set(gca,'XTickLabel'...)
I tried using
color = xlsread(fileName, 'A1:A3');
but it didn't convert the data into the right format.
Any help is appreciated.
The second output argument of xlsread contains text data. The first contains only numerical:
>> [nums,colors,raw] = xlsread('colorData.xlsx','A1:A3');
>> colors
colors =
'Red'
'Green'
'Blue'
UPDATE: The times read by xlsread are in Excel's serial date format (a numerical representation). They can be converted to a string with the time using datestr.
>> nums
nums =
0.0417
0.0833
0.1250
>> datestr(nums)
ans =
1:00 AM
2:00 AM
3:00 AM
These are actually dates, using Jan. 1 1900 as time zero. So, but giving just a time, it a number assuming this day. However, MATLAB uses Jan-1-0000, so if you have dates as well as times, convert them using datestr(t + datenum('30-Dec-1899')), where t is the numerical value with the serial date number.

how to plot time points in a day on excel

I have a set of points as time of day like
05:36:37
06:31:41
06:38:24
06:39:42
07:03:47
07:04:18
07:09:28
07:28:40
07:29:20
07:29:49
07:31:57
.....
Now i would like to plot this for an entire 24 hour range in a day.
Basically x axis is the 24 hour range and i need a point for every above time on the y axis. ofcourse y axis may not vary, but i am loooking at finding the coverage as to, in a day, when did the even occur more times. Its the same event. If there are better ways to represent you can also suggest that.
Let's say your data is from A1 to A_N.
in column B enter =HOUR(A1)
in column C enter =MINUTE(A1)
Then Insert -> XY Scatter Chart

Resources