gnuplot - 如何修改对数刻度图中的偏移量
问题描述
我想在下面的直方图中做几行堆叠
我选择了第一个解决方案,但我有一些不同的地方,因为我的 x 轴是对数刻度,直方图会出现错误的位置。
如果我在没有 log scale 的情况下进行绘图,那将是正确的。 没有日志 ,但如果我使用日志,情节不是我想要的。 日志版本
这是我的数据和代码
cat shared_improve.txt
# N Sort Build
2 0.0415 0.0203
4 0.0422 0.0231
8 0.0426 0.0217
16 0.0422 0.0206
32 0.0436 0.0214
64 0.0431 0.0238
128 0.0687 0.0276
256 0.3207 0.0277
512 0.0434 0.0318
1024 0.3241 0.0498
2048 0.2156 0.0756
4096 0.2206 0.1104
8192 0.5088 0.1803
16384 0.5429 0.3554
32768 0.2683 0.6023
65536 0.2916 1.1679
131072 0.2424 1.9058
262144 0.2779 2.1457
524288 0.3869 3.8198
1048576 0.4464 7.6622
2097152 0.6034 15.146
4194304 0.9236 30.152
8388608 1.6020 61.129
16777216 2.8925 120.464
33554432 5.5434 239.922
cat global_improve.txt
# N Sort Build
2 0.0747 0.0201
4 0.0702 0.0170
8 0.0880 0.0260
16 0.0608 0.0162
64 0.0623 0.0186
128 0.0659 0.0211
256 0.3593 0.0212
512 0.0567 0.0240
1024 0.3552 0.3038
2048 0.5106 0.0370
4096 0.5349 0.0590
8192 0.5215 0.0920
16384 0.5965 0.1671
32768 0.5179 0.2886
65536 0.5216 0.5452
131072 0.2529 1.2914
262144 0.5777 2.4295
524288 0.7484 4.3674
1048576 0.8304 8.5765
2097152 1.1448 17.0458
4194304 1.8410 36.0509
8388608 3.1218 67.5819
16777216 5.8081 138.0298
reset
set terminal png font " Times_New_Roman,12 "
set output "test.png"
set logscale x 2
set xtics 2
set xtics rotate out
set style fill solid border -1
set boxwidth 0.3/2
dx=0.5/2
offset=-0.1
set yrange[0:0.5]
plot [1:16]'shared_improve.txt' using ($1+offset):($2+$3) title "sort shared" linecolor rgb "#cc0000" with boxes ,\
'' using ($1+offset):3 title "build shared" linecolor rgb "#ff0000" with boxes ,\
'global_improve.txt' using ($1+offset+dx):($2+$3) title "sort global" linecolor rgb "#00cc00" with boxes ,\
'' using ($1+offset+dx):3 title "build global" linecolor rgb "#00ff00" with boxes
解决方案
如果您自己绘制框并设置偏移量,则必须考虑对数比例。在那里,要获得恒定的偏移量,您不必添加或减去一个值,而是乘以或除以某个值。
代码:
reset
set terminal png font "Times_New_Roman,12"
set output "test.png"
set key top left
set logscale x 2
set xtics 2
set xtics rotate out
set style fill solid border -1
set boxwidth 0.3
offset=1.15
plot [1.1:1500] \
'shared_improve.txt' u ($1/offset):($2+$3) w boxes lc rgb "#cc0000" ti "sort shared", \
'' u ($1/offset):3 w boxes lc rgb "#ff0000" ti "build shared", \
'global_improve.txt' u ($1*offset):($2+$3) w boxes lc rgb "#00cc00" ti "sort global",\
'' u ($1*offset):3 w boxes lc rgb "#00ff00" ti "build global"
set output
结果:
(某些 32 的值是(不?)故意缺失的?)
推荐阅读
- java - Java:Selenium WebElements 和 AssertThat 给出不正确的结果
- javascript - 选择组件以在打开后将组件移到下方
- ios - NSString initWithCoder,DequeueReusableCell 处的内存泄漏
- laravel-backpack - 在 store 函数中获取最后一个插入 id
- android - 我收到此错误。当我尝试使用 facebook 登录我的应用程序时:将您登录到此应用程序时出错
- c - 如何在 C 中使用双宏
- c - 不使用 clflush 逐出缓存行
- azure-ad-b2c - Azure AD B2C 自定义策略注册,仅使用预先填写的会员编号和电子邮件
- xamarin.forms - Xamarin 表单,滚动视图不会滚动到 StackLayout
- javascript - 具有对象属性拼接的角度对象 arr