堆栈图中的对数 x 轴 MatLab
Logarithmic x axis in a stackplot MatLab
我正在尝试根据 table 绘制堆栈图,以呈现具有相同 x 轴的多个变量。但是,我希望 x 轴是对数的。我在 stackplot 文档中找不到任何方法。有人对我如何解决这个问题有什么建议吗?
我曾尝试使用子图,但是,这样我的图表就无法在一页上全部显示,而且子图之间会有很多白色 space。因此,我选择了 stackplot 以使其更漂亮并且更少 space-消耗。
tbl = readtable('usage.csv');
newYlabels = {'Heating (kWh/year)','Cooling (kWh/year)','Electricity (kWh/year)'};
stackedplot(tbl,[{2:16},{17:27},{28:35}],'XVariable',[1],'DisplayLabels',newYlabels);
这是代码的输出:
这是我要制作的图像,但 x 轴必须是对数刻度的实变量 (\beta)
不幸的是,stackedplot
没有对数轴选项,并且由于它创建了一个 StackedAxes
而不是普通的 Axes
对象,因此无法更改它。
如果您想使用 stackedplot
的唯一原因是减少白色 space,您可能需要查看 tight_subplot
on the Matlab FEX。这将允许你做:set(ax, 'XScale', 'log')
.
然而,您可以获取 x
数据的 log
,并将其添加到 table:
tbl = readtable('outages.csv'); % sample data
tbl = sortrows(tbl, 'OutageTime'); % sort by date
% make x vector; for example just row numbers
x = (1:size(tbl,1)).';
xlog = log10(x);
% add x to table
tbl.Xlog = xlog;
tbl.X = x;
% plot normal x
f = figure(1); clf;
s = stackedplot(tbl, {'Loss'}, 'XVariable', 'X');
xlabel('rows');
% plot log(x)
f = figure(2); clf;
s = stackedplot(tbl, {'Loss'}, 'XVariable', 'Xlog');
xlabel('log(rows)')
正常:
日志:
我正在尝试根据 table 绘制堆栈图,以呈现具有相同 x 轴的多个变量。但是,我希望 x 轴是对数的。我在 stackplot 文档中找不到任何方法。有人对我如何解决这个问题有什么建议吗?
我曾尝试使用子图,但是,这样我的图表就无法在一页上全部显示,而且子图之间会有很多白色 space。因此,我选择了 stackplot 以使其更漂亮并且更少 space-消耗。
tbl = readtable('usage.csv');
newYlabels = {'Heating (kWh/year)','Cooling (kWh/year)','Electricity (kWh/year)'};
stackedplot(tbl,[{2:16},{17:27},{28:35}],'XVariable',[1],'DisplayLabels',newYlabels);
这是代码的输出:
这是我要制作的图像,但 x 轴必须是对数刻度的实变量 (\beta)
stackedplot
没有对数轴选项,并且由于它创建了一个 StackedAxes
而不是普通的 Axes
对象,因此无法更改它。
如果您想使用 stackedplot
的唯一原因是减少白色 space,您可能需要查看 tight_subplot
on the Matlab FEX。这将允许你做:set(ax, 'XScale', 'log')
.
然而,您可以获取 x
数据的 log
,并将其添加到 table:
tbl = readtable('outages.csv'); % sample data
tbl = sortrows(tbl, 'OutageTime'); % sort by date
% make x vector; for example just row numbers
x = (1:size(tbl,1)).';
xlog = log10(x);
% add x to table
tbl.Xlog = xlog;
tbl.X = x;
% plot normal x
f = figure(1); clf;
s = stackedplot(tbl, {'Loss'}, 'XVariable', 'X');
xlabel('rows');
% plot log(x)
f = figure(2); clf;
s = stackedplot(tbl, {'Loss'}, 'XVariable', 'Xlog');
xlabel('log(rows)')
正常:
日志: