I have plot that has dates for xaxis. The format is
set xdata time
set timefmt x "%Y%m%dT%H%M%S"
The actual data file has "date" only timestamps - i.e. not the following T part BUT plots correctly.
20130601
When I want to plot a vertical arrow I get no error - but no arrow either:
set arrow from 20130601,0 to 20130601,500000
When using time formats, the respective parts of the data file are read in as string. So for the arrow you must use
set arrow from "20130601",graph 0 to "20130601",graph 1
If you use integers, then they are interpreted as Unix timestamps, and 20130601 corresponds the the 21. August 1970. So you don't get an error, but the date is not in your range.
Related
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.
As shown in the screenshot: both axes are numeric. So why can not the trend line be calculated?
The problem with this set up is that the values on the x-axis are discrete values rather than a measure.
Tableau treats every number as a separate category rather than a point on an axis.
If you click on that field and chose "Convert to measure", you should get an actual scatterplot and you should then be able to add a reference line for each axis.
I'm unable to get date/time to work in gnuplot. Here's what seems right to me, errors described below.
set xdata time
set timefmt "%Y-%j/%H:%M:%S"
#set xrange ["2016-349/00:56:00":"2016-349/00:57:00"]
set format x "%H:%M:%S"
plot "-" using ($1):($2) with lines
2016-349/00:56:26.560000 0.587785252292582
2016-349/00:56:27.560000 1.59702608337727e-13
2016-349/00:56:28.560000 -0.587785252292324
e
pause mouse any
With set xrange commented out as shown, I get this warning.
Warning: empty x range [2016:2016], adjusting to [1995.84:2036.16]
and the x-axis doesn't appear to be based on the range of the data, with ticks from 00:33:15 to 00:34:00. The resulting plot is a vertical line at 00:33:36, but the points are part of a sine wave.
Uncommenting set xrange, I get this error instead.
line 6: all points y value undefined!
I get the same behavior with gnuplot 4.2 patchlevel 6, and 5.0 patchlevel 1. Thanks for any help you can provide.
Jim
The error is here:
plot "-" using ($1):($2) with lines
You can use $ only in expressions, otherwise just use numbers itself:
plot "-" using 1:2 with lines
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.
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