How can I show the model date in the plot in AnyLogic - simulation

I can use the time plot, but it shows the time in days not in dates. That is why I want to use plot, where I can give my model date using the function
date()
in the x-axis, but it is not working because we can only have double values in the plot.
Kindly let me know how I can achieve the date in the X-axis of the plot.

You can format the dates in the appearance section of the graphs, in the time axis format field

Related

Matlab date help on x-axis

I have a porkchop plot that looks similar to this:
The contour function used to make it has input arguments for the x and y positions that are serial dates (as that seemed to be required by MATLAB). Then I used the following command to get the format I want:
datetick('x', 2); datetick('y', 2);
The problem I am having is that when I zoom in on the plot the tick labels to not autogenerate and I can be left with no ticks on the x or y axis if I zoom in to use a weeks' date range for example.
I tried enabling 'auto' for XtickMode and YtickMode but when I zoom in or pan after using those commands the relationship between the independent and dependent variables are lost for some reason (aka the dates don't stay with data like they do when you just have numbers on the x axis and zoom in).
Any ideas on how to solve this issue to get the functionality I'm looking for?
I have also tried the command xtickformat('dd-MMM-yy') but I get an error "Invalid numeric tick label format." when I use it with the contour plot.
As far as I know there is no builtin method in MATLAB to do this. I use the datetickzoom function from the MATLAB FileExchange. If you replace all instances of datetick with datetickzoom, it will automatically update the relevant axis labels when you zoom in.

How do I place the Date and Time on my horizontal axis to be in separate rows in a figure in MATLAB?

I am plotting a graph of random data versus datetime strings. These datetime strings are all in one line and serve as labels on the horizontal axis. I would like the date to be displayed in one line and the time to be in another line.
The image below describes my graph. I would like the time to be displayed underneath the date.
The code I used to generate the graph is shown below:
figure
plot(sample(:,1),sample(:,2:5),'o')
tick=get(gca,'xtick');
set(gca,'xticklabel',datestr(tick,31))
drawnow()
How can I get the time of each horizontal label to appear below the date?
This is a bit of a hack, but you can introduce the TeX command \newline inside the date string in between the spaces of the date and the time, then set these new strings to be the X Tick labels in your figure. You'll need to convert the character array that is output from datestr into a cell array of strings with cellstr, then use strrep to perform the replacement from a space to \newline.
Something like this should work:
figure
plot(sample(:,1),sample(:,2:5),'o')
tick=get(gca,'xtick');
vals = cellstr(datestr(tick,31)); %// Change
new_vals = strrep(vals, ' ', '\newline'); %// New
set(gca,'xticklabel',new_vals); %// Change
drawnow()
When I do this with a sample plot:
plot(1:6, 1:6, 'r.');
I get this as the final result once I run the code:
Take note that this assumes that the X Ticks are sufficiently spaced apart from each other. Your plot will look cluttered if you have many ticks on the horizontal axis.

Adding date tick marks to a Matlab plot

I have a plot of time series data, and I would like to replace the tick marks of the x-axis (automatically I have the number of the ordered observations) with the date when the value is observed. I would like to have a tick mark every 5 years for example. I know how to do it with R, but with MATLAB seems so complicated and I'm not getting the result I want.
There is an answer on the Mathworks website that I think you will find helpful: http://www.mathworks.com/matlabcentral/answers/92565-how-do-i-control-axis-tick-labels-limits-and-axes-tick-locations. Basically what you want to do is manipulate the XTick or XTickLabel attributes of the current axis handle. Lets say I have a plot that spans 100 years from 1900 - 2000. After creating the plot, I can set year labels in 5 year increments by doing:
set(gca, 'XTick', 1900:5:2000);

Time on y axis - Matlab

I have plotted a figure with imagesc. The data was extracted from a file and the time was readed as a string column so I converted to double with datenum.
time = datenum(time, 'HH:MM:SS');
figure(1)
imagesc(freq,time,rssimat);
colorbar;
In this way it works but the picture looks like this
As you notice the y axis has this double numbers which represent the time converted with datenum. I actually would like to see my actual time like 'HH:MM:SS'.
Therefore I added a line:
datetick('y', 'HH:MM:SS');
And now my figure looks like...
It seems like you need to "zoom in" on Y axis. Your tracked interval appears to be very short in duration while on the Y axis you display the whole day.
Did you try: datetick('y', 'HH:MM:SS', 'keeplimits'); ? This will basically zoom in and fill the entire chart, while on the Y axis you will have HH:MM:SS format.
If you use datetick('y', 'HH:MM:SS', 'keepticks'); it will preserve the locations of the ticks while converting the labels to HH:MM:SS format.
u can use ylim function in matlab to limit your y-ranges

How do i display all the date in x axes

I am using Matlab to plot a graph but i am not getting all the date's in x axes. for example first date starts off 21/2/2013 next date continues as 21/2/2012 but it should be 21/2/2013, 24/2/2013 etc... is there a way to accomplish this? This is the syntax i am using for plotting my graph:
plot(dates,mean([h,l],2),'--r','LineWidth',2)
I am using date as an array, i found out that i can use Units but it does not work
Also is there any way i can add a graph side by side so first graph should appear on right side where the second graph should appear on left hand side. Is this to do with GUI or do i am have to position these graph specifically in a greed
there is a function for that
see
http://www.mathworks.com/help/finance/dateaxis.html
also make sure that the "dates" variable, holds the dates not strings (e.g. 744564)
You want to set the tick marks to something custom I believe. Assuming tickDates has all of the date values where you want a tick value:
plot(dates,mean([h,l],2),'--r','LineWidth',2)
set(gca,'XTicks',tickDates)
As far as side by side plotting, you want to use subplots.
subplot(2,1,1)
plot(dates,mean([h,l],2),'--r','LineWidth',2)
subplot(2,1,2)
For more, see http://www.mathworks.com/help/matlab/creating_plots/setting-axis-parameters.html