Today I'm having problems with the x-axis in MATLAB. I plot some daily quantities together with the dates.
quantline= plot( quantDates(1:end,1), quantwithdrawn, '-.b', 'LineWidth', 2) ;
BUT it doesn't matter what combination of datetick, set gca, xlim, etc. I try, the best x-axis numbering I can manage is:
I want at least 3 months for every year, how can I fix this?
Related
Introduction
Let's say I have two series of data, one of them in the function of "x", the second "1/x". I want to put it in a subplot, one by one. However because the scale of second plot is 1/x, it is impossible to compare this plots.
What I achieved
I can revert the order of the x-axis in the second plot, so in the best case, I can have something like this:
subplot(2,1,1);
plot(X,Y) %First plot
xlim([273 833])
xticks([350 500 650 800])
subplot(2,1,2);
plot(1./X,Z); %Second plot
xlim([1/833 1/273])
xticks([0.0013 0.0015 0.0020 0.0029])
set ( gca, 'xdir', 'reverse' ) %reverting the x-axis
The ticks are totally desynchronized. 350 should be in the one column with 2.9 (1/350=2.9*10^-3), 500 with 2, 650 with 1.5 and so on.
What I need
How to apply a non-linear x-axis or something similar, to get both axes synchronized? I know that it will be not the best idea, form the mathematical point of view, but it will be used only as a graphical, qualitative representation. The data I use is quite long, but If you have an idea how to solve it, you can use any random data to show.
I have to plot a time series data in MATLAB. The Y axis is a parameter taken six hourly for each day in a certain month of the year. And 44 such years have been taken into account. From 1958 to 2001. So the points on the X axis are 4*31*44=5456. How can I plot the data efficiently in MATLAB? The data file has two column vectors.
I have to plot the x axis so that it shows 44 July s from 1958 to 2001 . Each July has 124 points.
One for the time points (5456 points) so 5456 rows and other for the parameter measured. Thanks a lot.
As you don't give any more details, it is hard to know exactly what you are asking. If you have a matrix A with two columns, then you are looking for
plot( A(:,1), A(:,2) )
Alternatively, perhaps you want to see the histogram, hist, or the scatter plot scatter.
Well your X-axis(time data) is most probably not in datetime format & hence the problem.Once that is done, the plot will show what you want. You should try and change it to datetime & then try
plot(X,Y)
or
plot(A(:,1),A(:,2))
whichever be your data format
I need to make graphs, where X axis is a date and Y is a value. All calculations are made using Simulink. The problem is that scopes display default Simulink time in their X axis. Is there anything I can change, to make described graphs?
You can use plot function to get the desired graph with day of the month on the x-axis. The Graph can be for a particular month.
Example:
For the Month of May and dates 1st, 7th, 14th and 28th-
x=[1 7 14 28];
>> y=[2 10 3 1];
>> plot(x,y)
However, you need to make sure you import the data into 'y' variable correctly (from simulation output variable) so that it corresponds to your x-axis date-wise data.
I am implementing a Matlab script in which I would like to plot a function as follows:
figure;
plot(Flows(:,1),Flows(:,2));
title(strcat('f',num2str(j),'\_2013\_0',num2str(k)));
xlabel('Timestamp');
ylabel('Energy flow');
set(gca, 'XTickLabel', datestr(Flows(:,1)));
Flows is a matrix which takes as input a csv file where the first column is a Timestamp value. There are 12 files, each one for every month. In a loop, I read the files and create the matrix.
Flows(i,1)=datenum(Input{i,1}{1,1},'YYYY-mm-DD HH:MM:SS');
Flows(i,2)=Input{i,1}{1,7};
However, when I plot the trend the x axis only shows date from 1st of January 00:00 until 1st of January 00:36. How could I display in the x axis, at least, from 1s of "Month" until the end of the month? I suspect the problem comes from the mask of the translation of the data from num to date, but I have tried several masks, which one is the suitable?
Finally, I've added these lines:
set(gca,'XLim',[min(Flows(:,1)) max(Flows(:,1))]);
set(gca,'XTick',Flows(:,1));
set(gca, 'XTickLabel', datestr(Flows(:,1)));
But, when I'm going to plot the trend, I get the following Exception,
Values must be monotonically increasing
I really can't find a solution to this:
I need to plot a timeseries of three years daily data on the same plot as three years monthly data (same y-scale = euros), but tried all the other threads talking about this without being able to figure it out. Any help?
It would be nice if the x-axis said the months, but numbers are just fine if it's too complicated...
thanks
A
How about this?
t = 1:365*3; %// example without leap year
y = randn(size(t)); %// example data
plot(linspace(1,37,numel(t)),y) %// x axis with 36 month periods
xlim([1,37])
set(gca,'xtick',1.5:4:37) %// ".5" to place tick at middle of each month
set(gca,'xticklabel',{'Jan','May','Sep'})