如何使虚线与gnuplot中的十字准线相交? [英] How to make dashed grid lines intersect making crosshairs in gnuplot?

查看:128
本文介绍了如何使虚线与gnuplot中的十字准线相交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制一些数据,我想使用虚线网格线.

I'm plotting some data and I want to use dashed grid lines.

任何虚线网格都可以,但是我更喜欢长破折号,短破折号,长破折号"格式.

Any dashed grid line would suffice, but I prefer a "long dash, short dash, long dash" format.

例如,给出以下代码

set grid lc rgb "#000000" lt 1 dt (50, 25, 20, 25)
plot x**2

我得到这个结果

但是我宁愿网格线相交总是发生在两个破折号的中间,像这样

But I would rather the grid lines intersection to happen always at the middle of two dashes, like this

如果我可以使水平网格线与垂直网格线不同,并且可以为每个网格线添加一些偏移量,那么我会想象有一种方法可以实现这一点.但我似乎也无法做到这一点.

If I could make horizontal grid lines different to vertical grid lines and I could add some offset to each one, then I'd imagine there's a way to accomplish this. But I can't seem to do that either.

推荐答案

看来gnuplot不能为x-grid和y-grid使用两种不同的短划线样式. 我目前看到的一种解决方法是在彼此之上绘制两个相同的图.一个带有适当的x网格线,另一个带有适当的y网格线.

It looks like gnuplot cannot have two different dashstyles for x-grid and y-grid. One workaround I see currently is to plot two identical plot on top of each other. One with appropriate x-grid lines and the other with appropriate y-grid lines.

如果要使用比例为(50-25-20-25)的虚线图案,则它对应于两个抽签之间的(25-25-20-25-25-0)(5-5-4-5-5-0). 此外,破折号和间隙长度数字,例如在dt (50,25,20,25)中,似乎与图形大小具有固定的关系. 经验"因子近似为11(至少对于我在gnuplot 5.2.6下测试的wxt终端而言).

If you want a dash pattern with proportions of (50-25-20-25), this correspond to (25-25-20-25-25-0) or (5-5-4-5-5-0) between two tics. Furthermore, the dash and gap length numbers, e.g. in dt (50,25,20,25), seem to be in a fixed relation to the graph size. The "empirical" factor is 11 with good approximation (at least for the wxt terminal which I tested under gnuplot 5.2.6).

实际上,以下代码在qt终端上给出了不同的结果.这不仅仅是一个不同的因素.如果不了解源代码,它会变得更加复杂,并且可能很难解决.因此,以下内容似乎适用于wxt终端(甚至可能仅在Windows下?)可能是一个幸运的打击.

actually, the code below gives different results with a qt terminal. And it's not just a different factor. It's more complicated and probably difficult to solve without insight into the source code. So, the fact that the following seems to work with wxt terminal (maybe even just under Windows?) was probably a lucky strike.

这样,您可以自动创建虚线,从而在主要网格线的相交处产生十字准线.

With this you can create your dash lines automatically resulting in crosshairs at the intersections of the major grid lines.

假设是:

  1. 您的第一个和最后一个抽动症在边界上
  2. 您知道x和y间隔的数量

您还需要了解图形大小.这些值存储在变量GPVAL_TERM...中,但仅在绘制后中存储.因此,您必须replot才能获取正确的值.

You also need to know the graph size. These values are stored in the variables GPVAL_TERM..., but only after plotting. That's why you have to replot to get the correct values.

此解决方法至少应始终在主要网格线的相交处给出十字准线.

This workaround at least should give always crosshairs at the intersection of the major grid lines.

仅用于完整性".在不同终端上获得相同(或相似)外观的定制虚线的因素差异很大. wxt约11,qt约. 5.6,pngcairo约0.25.这不是我所期望的.此外,看起来这些因素稍微取决于x和y以及图形大小.为了获得精确"的十字准线,您可能需要进一步调整这些数字.

Edit 2: just for "completeness". The factors to get the same (or similar) looking custom dashed pattern on different terminals varies considerably. wxt approx. 11, qt approx. 5.6, pngcairoapprox. 0.25. This is not what I would expect. Furthermore, it looks like the factors slightly depend on x and y as well as graph size. In order to get "exact" crosshairs you might have to tweak these numbers a little further.

代码:

### dashed grid lines with crosshairs at intersections
reset session

TERM = "wxt"   # choose terminal

if (TERM eq "wxt") {
    set term wxt size 800,600
    FactorX = 11.    # wxt
    FactorY = 11.    # wxt
}
if (TERM eq "qt") {
    set term qt size 800,600
    FactorX = 5.58  # qt
    FactorY = 5.575   # qt
}
if (TERM eq "pngcairo") {
    set term pngcairo size 800,600
    set output "tbDashTest.png"
    FactorX = 0.249    # pngcairo
    FactorY = 0.251    # pngcairo
}

set multiplot
set ticscale 0,0

Units = 24   # pattern (5,5,4,5,5,0) are 24 units

# set interval and repetition parameters
IntervalsY = 10
RepetitionsY = 1
IntervalsX = 4
RepetitionsX = 3

# initial plot to get graph size
plot x**2
gX = real(GPVAL_TERM_YMAX-GPVAL_TERM_YMIN)/IntervalsY/Units/FactorY/RepetitionsY
gY = real(GPVAL_TERM_XMAX-GPVAL_TERM_XMIN)/IntervalsX/Units/FactorX/RepetitionsX
# first plot with x-grid lines
set grid xtics lt 1 lc rgb "black" dt (gX*5,gX*5,gX*4,gX*5,gX*5,0)
replot
unset grid
# second plot with y-grid lines
set grid ytics lt 1 lc rgb "black" dt (gY*5,gY*5,gY*4,gY*5,gY*5,0)
replot

unset multiplot
set output
### end of code

结果:

这篇关于如何使虚线与gnuplot中的十字准线相交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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