英文:
I want to plot the histogram using gnuplot. And it doesn't work
问题
以下是您要翻译的内容:
set term postscript eps
set output "result.eps"
set style data histogram
set style histogram rowstacked
set style fill solid 0.5
set boxwidth 1 relative
set xrange [0:31]
set xtics 1
set yrange [0:15]
set ytics 1
set title 'Studying time in May'
datafile = '../data/hour_formatting/May_formatted.txt'
data_under = '../data/under_ave/May_under.txt'
plot datafile using 2:xtic(1) with boxes title 'Studying time', data_under using 2:xtic(1) with boxes notitle fillcolor 'red'
在data_under
中,只有超过平均值的值为0。
但是整个图形都以灰色着色。
我只想为平均值以下的值着色。问题在哪里,我该如何解决?
我不知道问题在哪里,所以我什么都没尝试过。
英文:
set term postscript eps
set output "result.eps"
set style data histogram
set style histogram rowstacked
set style fill solid 0.5
set boxwidth 1 relative
set xrange [0:31]
set xtics 1
set yrange [0:15]
set ytics 1
set title 'Studying time in May'
datafile = '../data/hour_formatting/May_formatted.txt'
data_under = '../data/under_ave/May_under.txt'
plot datafile using 2:xtic(1) with boxes title 'Studying time', data_under using 2:xtic(1) with boxes notitle fillcolor 'red''
In data_under, there is the data that 0 value only for above average value.
But the graph all colored with gray color.
I want to color only for the value below the average value. What is the problem, and how can I solve it?
I don't know what is the problem, so I cannot tried anything.
答案1
得分: 0
Ethan已经在postscript终端中提到了有关颜色的提示。
另请参阅这个问题。
看起来您已经使用了某个软件工具将数据拆分为高于和低于平均水平的部分。
让我建议您如何可以使用gnuplot从一个包含您的数据的单个文件(或数据块)来完成这个操作,即每天某个月份的学习时间以小时为单位。
脚本:
### 显示具有不同颜色的低于平均水平的条形图
reset session
# 创建一些随机测试数据
set table $Data
set samples 30
plot '+' u ($0+1):(rand(0)*9 * int(rand(0)+0.8)) w table
unset table
stats $Data u 2 nooutput
myColor(v) = v < STATS_mean ? 0xff0000 : 0xcccccc
set style fill solid 1.0 border lt -1
set xrange[0:32]
set xtics out
set ylabel "每日学习时间(小时)"
plot $Data u 1:2:(myColor($2)):xtic(1) w boxes lc rgb var notitle, \
STATS_mean w l dt 2 lc "black" ti "平均值"
### 脚本结束
结果:
英文:
Ethan already gave the hint about color in postscript terminal.
See also this question.
It looks like you have used some software tool to split your data into above and below average.
Let me make a suggestion how you can simply do it with gnuplot from one single file (or datablock) containing your data, i.e. study time in hours per day of a certain month.
Script:
### show bar chart with differently colored bars below average
reset session
# create some random test data
set table $Data
set samples 30
plot '+' u ($0+1):(rand(0)*9 * int(rand(0)+0.8)) w table
unset table
stats $Data u 2 nooutput
myColor(v) = v < STATS_mean ? 0xff0000 : 0xcccccc
set style fill solid 1.0 border lt -1
set xrange[0:32]
set xtics out
set ylabel "studying time in hours"
plot $Data u 1:2:(myColor($2)):xtic(1) w boxes lc rgb var notitle, \
STATS_mean w l dt 2 lc "black" ti "average"
### end of script
Result:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论