Filter löschen
Filter löschen

How to draw line logarithmic x axis and y axis

3 Ansichten (letzte 30 Tage)
Rizwan Khan
Rizwan Khan am 7 Sep. 2020
Kommentiert: Adam Danz am 14 Sep. 2020
Hi All,
I have some financial data price and time.
I need to plot it on a chart, however, i want the Y axis to be a log scale and the x axis to be a log scale
so both need to be log scaled.
How can i do this?
  6 Kommentare
Rizwan Khan
Rizwan Khan am 13 Sep. 2020
@Adam - Can you expand a little further on what your suggesting, i didn't quite understand you
Adam Danz
Adam Danz am 14 Sep. 2020
See my answer below.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Mario Malic
Mario Malic am 7 Sep. 2020
  3 Kommentare
Rizwan Khan
Rizwan Khan am 7 Sep. 2020
This is the error i get when using loglog or even plot with the time data format above
It wants a numeric
Error using loglog
Data inputs must match the axis configuration. A numeric axis must have numeric data inputs or data inputs which can be converted to double.
Rizwan Khan
Rizwan Khan am 7 Sep. 2020
I tried using xtickformat('yyyy-MM');
However, i then get the error that this time format does not support log scale?
The coordinate system or ruler class does not support log axis scale.

Melden Sie sich an, um zu kommentieren.


Adam Danz
Adam Danz am 14 Sep. 2020
Bearbeitet: Adam Danz am 14 Sep. 2020
Convert the dates to duration from the starting date but use the numeric form of the durations (ie, not the "duration' class). Then you're just working with regular old numbers that can sustain the log scale.
If you want to see the date for each point, add the dates to the datatips.
Demo:
% Create date-time vector and data
dt = datetime(2020,1,1) + days(0:5:365);
data = exp(1:numel(dt));
% Compute number of days since the start of dt.
ndays = days(dt - dt(1));
% Plot data and show starting date in xlabel
h = loglog(ndays,data, 'o');
xlabel(sprintf('Number of days since %s',datestr(dt(1))))
% Now add the dates to each marker in their datatip.
h.DataTipTemplate.DataTipRows(end+1) = dataTipTextRow('Date',dt);
X is the number of days since the first datetime value.
Date shows the datatime value for each data point.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by