Plot two timeseries with different x-axis - matlab

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'})

Related

Working in jupyter, trying to plot time series

I just want to use any simple seaborn or matplot plot to visualize my data set as a lineplot. Please help. I cant seem to figure out how to plot these values i keep getting all types of errors.
My data set consists of 4 columns, the first is date which I want to plot on my x axis and the rest are numeric values of gold, oil and the dollar that I want to plot.
I have my dates set to datetime value and the rest set to float64, I am trying to plot the fluctuations of oil, gold and the dollar over time to look at any possible correlation. Sorry for any obvious mistakes I am not an expert.
Doing This gives me only one plotted value and the Date values on x axis is incorrect
plt.xlabel('Date')
plt.ylabel('Values')
plt.title('Historical Data')
df['Price_Gold'].plot()
So basically im running into trouble when trying to plot multiple values against time.
df.plot(x='Date', y=['Col1', 'Col2'])
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html

Plot time series data in MATLAB

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

MATLAB Simulink scope with text in X axis

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.

Set number of labels on my x-axis

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?

interpolation of fortnightly annual temperature data into hourly measurements in matlab

I have a dataset of annual temperature measurements recorded at fortnightly intervals. The data looks similar to the following:
t = 1:14:365;
% GENERATE DATA
y = 1 + (30-1).*rand(1,length(t));
y1 = 20*sin(2*pi*t/max(t)); % Annual variation °C
y1(y1<0) = [];
tt = 365/14;
time = 1:tt:365;
plot(time,y1,'-o');
where it clearly follows a annual temperature cycle.
From this I am wondering if it is possible to add a sine function (which would represent a diurnal temperature range) onto the data? For example, from the fortnightly data, if we were to interpolate the series to have 8760 measurements i.e. hourly measurements, for the series to be believable it would need to be characterized by a diurnal temperature cycle in addition to the annual temperature cycle. Furthermore, the diurnal temperature cycle would need to be a function of the temperature measurements at that time i.e. would be greater in the summer than in winter. So maybe it would be better to firstly use linear interpolation to get the data to represents hourly intervals and then add the sine function. Is there a method for writing this into a script? or does anyone have an opinion on how to accurately achieve this?
You could first interpolate your data (down to 1 hours) using something like
x = 1:inv(24):365;
T_interp = interp1(t,y1,x,'spline');
Check out Matlab documentation for interp1 (example 2)
and then add a sine onto it. The following a sine of period 1 (24 hours) with amplitude A, with a minimum at 3am.
T_diurn = -A*sin(2*pi*x+(3/24)*2*pi);
Then
T_total = T_diurn + T_interp;
First: you know that good-looking plots are the most misleading things in existence? Interpolating data gathered every 14 days so that it will look like data collected every hour is considered at least bad practice most circles...
Having said that, I would use splines to do the interpolation -- they are a lot more flexible when it comes to changing from fortnightly and hourly to some arbitrary other combination, plus the annual temperature variation will be a lot smoother.
Here's how:
% Create spline through data
pp = spline(time, y1);
% define diurnal variation (this one is minimal at 4 AM)
T_diurn = #(t) -A*cos(2*pi*(t-(4/24)));
% plot example
t = 150 : 1/24 : 250;
plot( t, ppval(pp,t)+T_diurn(t) , 'b')