How can one draw a plot of this table?

1 view (last 30 days)
alpedhuez on 30 Jul 2021
Reopened: Cris LaPierre on 30 Jul 2021
Suppose I have table T
date visiors sales
1/1/2021 3 100
1/2/2021 5 120
I want to draw a plot of "visitors" and "sales" with date on the x axis. How can one do this?

Accepted Answer

Dave B
Dave B on 30 Jul 2021
Edited: Dave B on 30 Jul 2021
If you want a simple line plot, you could do
plot(, T.visitors)
hold on
plot(, T.sales)
plot(, [T.visitors T.sales])
or even:
plot(, T.visitors,, T.sales)
For a bar chart you might do:
bar(, [T.visitors T.sales])
Lot's more options for different visualizations can be found here
Dave B
Dave B on 30 Jul 2021
You can do this with:
stackedplot(T, {{'visitors' 'sales'}}, 'XVariable', 'Date')
The {{ might be confusing: you can think of this as: each element of the outer cell is an axes, each element of the inner cell is a line in that axes.
This definitely makes more sense when you have multiple plots to 'stack'.

Sign in to comment.

More Answers (0)





Community Treasure Hunt

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

Start Hunting!

Translated by