如何在Gnuplot中显示堆叠的条形图? [英] How to display a stacked barchart in Gnuplot?
问题描述
我有一个看起来像这样的数据文件:
I have a data file that looks a bit like this:
A 0.2 0.5
B 0.65 0.8
C 0.4 0.2
即,它包含三列,第一列包含标签,另一列两列浮点值。列用空格隔开。
i.e., it contains three columns where the first column contains labels and the other two columns float values. Columns are separated by spaces.
我想以这样的方式绘制此图,即标签在X轴上显示为tic,而列则绘制为两个不同的图
I'd like to plot this in a way that the labels appear as tics on the x-axis while the columns are plotted as two differently colored barcharts on top of each other.
如何使用Gnuplot实现此目的?
How can I achieve this using Gnuplot?
推荐答案
假设您的数据存储在文件 1.dat
中,则可能会生成堆叠的条形图,如下所示:
Assuming your data are stored in the file 1.dat
, stacked barcharts might be generated as follows:
set style data histograms
set style histogram rowstacked
set boxwidth 1 relative
set style fill solid 1.0 border -1
set yrange [0:1.5]
set datafile separator " "
plot '1.dat' using 2 t "Var 1", '' using 3:xticlabels(1) t "Var 2"
如您所见,条形图与直方图没有区别(至少在Gnuplot内部)。可以在gnuplot 演示页面上找到更多信息。
As you can see, barcharts are no different from histograms (at least, from within Gnuplot). More information can be found on gnuplot demo page.
这篇关于如何在Gnuplot中显示堆叠的条形图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!