如何防止Xtick标签过于狭窄? [英] How to prevent xtick labels too cramped?

查看:66
本文介绍了如何防止Xtick标签过于狭窄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过gnuplot自动生成的xticks,我们经常发现标签太紧/狭窄,如该快照所示. 我们如何解决这个问题?

With xticks automatically generated by gnuplot we find too often that the labels are too tight / cramped together as shown in this snapshot. How can we fix this issue?

推荐答案

这是一个非常粗糙的解决方法.这个想法是告诉人们想要多少个(大约)刻度线标签,并根据整个绘图范围让gnuplot将其转换"为合适的刻度线间距.

This is a very crude workaround. The idea is telling how many (approximate) number of tick labels one wants, and have gnuplot "translate" that into a suitable tick spacing according to the whole plotting range.

我正在发布我现在正在使用的内容,并且效果很好. 花费xmin = 0. 您可以猜测它的工作方式并对其进行调整.

I am posting what I am using now, and it works reasonably well. It takes xmin=0. You could guess the way it works and tune it.

# Get/print stats about input data, ...
stats "output.csv"  using 2:5  nooutput
# ... and use them for setting the number of tick labels for x axes, to avoid overlap
#tmin = STATS_min_x
tmin = 0
tmax = STATS_max_x
nxtics = 5                        # Tune this
# Do not count 0 as a tick
nxtics = nxtics - 1
# Shift numbers to the range [1,10)
ttic1 = tmax / nxtics
nshift_digits = -floor(log10(ttic1))
shift = 10.0**nshift_digits
tmax_shift = tmax * shift
ttic1_shift = ttic1 * shift
# ttic1_shift should be between [1,10)
# Use (arbitrary) specified tick spacing (here at 1, 2, 5 in the first significant digit, but one could use others, including 2.5, e.g.), which better matches the data range and selected number of tick labels. Note that the number of tick labels would not be strictly maintained.
# Tune these numbers
ttic_shift = 1.0
if (ttic1_shift < 1.3) {
    ttic_shift = 1.0
} else { if (ttic1_shift < 3.0) {
    ttic_shift = 2.0
} else { if (ttic1_shift < 7.0) {
    ttic_shift = 5.0
} else {
    ttic_shift = 10.0
} } }
ttic = ttic_shift / shift
print "ttic=", ttic

PS:尽管我没有尝试辛苦",但我仍然无法实现 .我猜想该解决方案可能适用于单个绘制的数据集,但不确定它是否适用于多个数据集.

PS: I could not have this working, although I did not try "hard". I guess that solution might work for a single plotted dataset, but not sure it would work for more than one.

这篇关于如何防止Xtick标签过于狭窄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆