【问题标题】:gnuplot: string values xticlabel & adjusting fontsizegnuplot:字符串值 xticlabel 和调整字体大小
【发布时间】:2018-03-12 16:36:12
【问题描述】:

我想以直方图样式绘制数据,顶部带有“累积”曲线。我有以下问题:

我的数据由一列包含类别(“放电”)和一列包含属于相应类别的值的数量(“概率”)组成。类别列的最后一个值是“>100”,汇总了所有排放量大于最后一个数值(“100 m^3/s”)的发电厂。我还没有找到使用命令plot 'datafile.dat' using 1:2 with boxes ... 绘制最后一个类别和相应值的解决方案,因为(我假设)在这种情况下,只有 x-ticlabels 的数值被读出,所以最后一个类别丢失了。如果

我用这个命令plot 'datafile.dat' using 2:xtics(1) with boxes ... 绘制它,最后一个类别“>100”绘制得很好。

但是:如果我使用后一个命令,x 轴标签会以正常字体大小显示。即使我的代码中有set format x '\footnotesize \%10.0f' 行。

我已经阅读了plotcommand 行中的显式标签,这些标签覆盖了之前设置的格式样式,但无法使其适应我的代码。 Changing ytic font size in gnuplot epslatex (multiplot)

你知道怎么做吗?

Excel 截图可视化我想要实现的目标

'datafile.dat'
discharge probability cumulated
10 20 20% 
20 10 10%
30 5 5%
40 6 6%
50 4 4%
60 12 12%
70 8 8%
80 15 15%
90 20 20%
100 6 6%
>100 4 4%`

[terminal=epslatex,terminaloptions={size 15cm, 8cm font ",10"}]
set xrange [*:*]
set yrange [0:20]
set y2range [0:100]
set xlabel 'Discharge$' offset 0,-1
set ylabel 'No. of power plants' offset 10.5
set y2label 'Cumulated probability' offset -10
set format xy '$\%g$'
set format x '\footnotesize \%10.0f'
set format y '\footnotesize \%10.0f'
set format y2 '\footnotesize \%10.0f'
set xtics rotate by 45 center offset 0,-1
set style fill pattern border -1
set boxwidth 0.3 relative
set style line 1 lt 1 lc rgb 'black' lw 2 pt 6 ps 1 dt 2
plot 'datafile.dat' using 1:2 with boxes axes x1y1 fs pattern 6 lc black notitle, \
'datafile.dat' using 1:3 with linespoints axes x1y2 ls 1 notitle

【问题讨论】:

  • 看起来链接的情节正是你想要的——你有一个“更大”的类别,累积曲线一直上升到 100%。这是你的代码给你的,还是你想要实现的?如果是后者,请发布您迄今为止创建的数据文件和 gnuplot 脚本。
  • 我很抱歉 - 我花了一些时间来适应编码(我知道我应该首先尝试找出这一点......我很抱歉)。我更新了原来的问题:我希望现在更清楚......

标签: gnuplot


【解决方案1】:

我对你的数据文件感到困惑;第三列的数字似乎不是累积的,加起来也不是 100%。这是一个仅使用文件前两列的解决方案:

set term epslatex standalone header "\\usepackage[T1]{fontenc}"
set output 'test.tex'

stats "datafile.dat" using 2
total = STATS_sum

set xlabel "Discharge" offset 0, 1.5
set xtics rotate

set ylabel "No. of power plants"
set ytics nomirror
set yrange [0:*]

set y2label "Cumulative probability"
set y2tics
set y2range [0:]

set boxwidth 0.3 relative
set style line 1 lt 1 lc rgb 'black' lw 2 pt 6 ps 1 dt 2

plot \
'datafile.dat' using 2:xtic("\\footnotesize " . stringcolumn(1)) with boxes axes x1y1 fs pattern 6 lc black notitle, \
'datafile.dat' using ($2/total) smooth cumulative with linespoints axes x1y2 ls 1 notitle

set output

诀窍是在using 命令的每个标签前添加latex 命令\footnotesize。它还首先计算发电厂的总数以便计算概率,然后使用smooth cumulative 选项计算累积值。

【讨论】:

  • 太棒了!非常感谢 - 这正是我要找的东西!很抱歉与累积值混淆:这不是我的真实数据,我显然编造了一些愚蠢的示例值。 .. 一个后续问题:我想在每个类别中绘制两个不同的框(“有 c.p 的概率”和没有 c. 的概率)。为了使这两个框与放电的 xtics 对称,我使用了在我得到你的解决方案之前的这段代码:plot ... using ($1-0.2):2 ...plot ... using ($1+0.2):4 ...我试图让它适应你的解决方案,但到目前为止失败了)。你有什么想法吗?
  • 存储在数据文件第一列的值不用于 x 坐标值,而仅用作刻度标签的字符串(它们甚至不必是数字)。图中的框出现在 x 位置 0、1、..、11(数据文件中的行号)。要相对于它移动框,请尝试... using ($0-0.2):2 ....
  • 感谢您的回答。不幸的是,我不明白如何将解决方案与($0-0.2) 集成到我需要正确格式的 ticlabels 的命令中(正如您在答案中建议的那样)。我尝试了以下变体,但没有任何效果...using 2:($xtic("\\footnotesize ".stringcolumn(1))-0.2)using 2:(xtic("\\footnotesize ".stringcolumn($1))-0.2)using 2:(xtic("\\footnotesize ".$stringcolumn(1))-0.2)
  • 在上述脚本中,将 plot 命令替换为plot 'datafile.dat' using ($0-0.2):2 with boxes axes x1y1 fs pattern 6 lc black notitle, 'datafile.dat' using ($0+0.2):2 with boxes axes x1y1 fs pattern 7 lc black notitle, 'datafile.dat' using 0:2:xtic("\\footnotesize " . stringcolumn(1)) notitle。此命令将一组框向左移动一点,将另一组框向右移动一点,然后分别打印 xtic 标签。
  • 非常感谢您的帮助!现在看起来我想要它!
猜你喜欢
  • 1970-01-01
  • 2014-07-15
  • 2017-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-18
  • 1970-01-01
相关资源
最近更新 更多