【问题标题】:Gnuplot: inset from file .pltGnuplot:来自文件 .plt 的插图
【发布时间】:2018-06-11 12:20:13
【问题描述】:

我有 2 个通用 Gnuplot 文件:plot1.pltplot2.plt 已保存。 我需要将它们合并到一个图中,其中plot2.pltplot1.plt 的插入。

我想我可以用图片更好地解释。 比方说,最终的结果应该是这样的

在这张图片中plot2.plt 是插图,主图是plot1.plt。每个文件都可以正确且独立地加载到 Gnuplot 中。

感谢您的建议。

编辑: 代码是(但它不能正常工作)是这样的:

set multiplot

load "plot1.plt"           # plot main figure

set size 0.6, 0.5       # set size of inset
set origin 0.4, 0.5     # move bottom left corner of inset
load "plot2.plt"             # plot inset

unset multiplot

plot1.pltplot2.plt 是通用绘图文件。为了不让它变得更复杂,你可以用这种方式生成它们:

plot sin(x)
save "plot1.plt"     #or choose your folder
plot exp(x)
save "plot2.plt"     #or choose your folder

以上代码产生:

What I get from the code above

不幸的是,为插图设置不同的大小或原点不会影响结果。 我正在使用 GNUPLOT 5.0 补丁级别 4。 对不起,我的英语不好,我不是母语人士。请随时修正语法/拼写。

编辑 2: 我现在提供文件plot1.plt 的代码。如果您认为它太长,请随时编辑和删除(全部或部分)。

#!/gnuplot
#
#    
#       G N U P L O T
#       Version 5.0 patchlevel 4    last modified 2016-07-21 
#    
#       Copyright (C) 1986-1993, 1998, 2004, 2007-2016
#       Thomas Williams, Colin Kelley and many others
#    
#       gnuplot home:     http://www.gnuplot.info
#       faq, bugs, etc:   type "help FAQ"
#       immediate help:   type "help"  (plot window: hit 'h')
# set terminal wxt 0 enhanced
# set output
unset clip points
set clip one
unset clip two
set bar 1.000000 front
set border 31 front lt black linewidth 1.000 dashtype solid
set zdata 
set ydata 
set xdata 
set y2data 
set x2data 
set boxwidth
set style fill  empty border
set style rectangle back fc  bgnd fillstyle   solid 1.00 border lt -1
set style circle radius graph 0.02, first 0.00000, 0.00000 
set style ellipse size graph 0.05, 0.03, first 0.00000 angle 0 units xy
set dummy x, y
set format x "% h" 
set format y "% h" 
set format x2 "% h" 
set format y2 "% h" 
set format z "% h" 
set format cb "% h" 
set format r "% h" 
set timefmt "%d/%m/%y,%H:%M"
set angles radians
set tics back
unset grid
set raxis
set style parallel front  lt black linewidth 2.000 dashtype solid
set key title "" center
set key inside right top vertical Right noreverse enhanced autotitle nobox
set key noinvert samplen 4 spacing 1 width 0 height 0 
set key maxcolumns 0 maxrows 0
set key noopaque
unset label
unset arrow
set style increment default
unset style line
unset style arrow
set style histogram clustered gap 2 title textcolor lt -1
unset object
set style textbox transparent margins  1.0,  1.0 border
unset logscale
set offsets 0, 0, 0, 0
set pointsize 1
set pointintervalbox 1
set encoding default
unset polar
unset parametric
unset decimalsign
set view 60, 30, 1, 1
set samples 100, 100
set isosamples 10, 10
set surface 
unset contour
set cntrlabel  format '%8.3g' font '' start 5 interval 20
set mapping cartesian
set datafile separator whitespace
unset hidden3d
set cntrparam order 4
set cntrparam linear
set cntrparam levels auto 5
set cntrparam points 5
set size ratio 0 1,1
set origin 0,0
set style data points
set style function lines
unset xzeroaxis
unset yzeroaxis
unset zzeroaxis
unset x2zeroaxis
unset y2zeroaxis
set xyplane relative 0.5
set tics scale  1, 0.5, 1, 1, 1
set mxtics default
set mytics default
set mztics default
set mx2tics default
set my2tics default
set mcbtics default
set mrtics default
set xtics border in scale 1,0.5 mirror norotate  autojustify
set xtics  norangelimit autofreq 
set ytics border in scale 1,0.5 mirror norotate  autojustify
set ytics  norangelimit autofreq 
set ztics border in scale 1,0.5 nomirror norotate  autojustify
set ztics  norangelimit autofreq 
unset x2tics
unset y2tics
set cbtics border in scale 1,0.5 mirror norotate  autojustify
set cbtics  norangelimit autofreq 
set rtics axis in scale 1,0.5 nomirror norotate  autojustify
set rtics  norangelimit autofreq 
unset paxis 1 tics
unset paxis 2 tics
unset paxis 3 tics
unset paxis 4 tics
unset paxis 5 tics
unset paxis 6 tics
unset paxis 7 tics
set title "" 
set title  font "" norotate
set timestamp bottom 
set timestamp "" 
set timestamp  font "" norotate
set rrange [ * : * ] noreverse nowriteback
set trange [ * : * ] noreverse nowriteback
set urange [ * : * ] noreverse nowriteback
set vrange [ * : * ] noreverse nowriteback
set xlabel "" 
set xlabel  font "" textcolor lt -1 norotate
set x2label "" 
set x2label  font "" textcolor lt -1 norotate
set xrange [ * : * ] noreverse nowriteback
set x2range [ * : * ] noreverse nowriteback
set ylabel "" 
set ylabel  font "" textcolor lt -1 rotate by -270
set y2label "" 
set y2label  font "" textcolor lt -1 rotate by -270
set yrange [ * : * ] noreverse nowriteback
set y2range [ * : * ] noreverse nowriteback
set zlabel "" 
set zlabel  font "" textcolor lt -1 norotate
set zrange [ * : * ] noreverse nowriteback
set cblabel "" 
set cblabel  font "" textcolor lt -1 rotate by -270
set cbrange [ * : * ] noreverse nowriteback
set paxis 1 range [ * : * ] noreverse nowriteback
set paxis 2 range [ * : * ] noreverse nowriteback
set paxis 3 range [ * : * ] noreverse nowriteback
set paxis 4 range [ * : * ] noreverse nowriteback
set paxis 5 range [ * : * ] noreverse nowriteback
set paxis 6 range [ * : * ] noreverse nowriteback
set paxis 7 range [ * : * ] noreverse nowriteback
set zero 1e-008
set lmargin  -1
set bmargin  -1
set rmargin  -1
set tmargin  -1
set locale "Italian_Italy.1252"
set pm3d explicit at s
set pm3d scansautomatic
set pm3d interpolate 1,1 flush begin noftriangles noborder corners2color mean
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB 
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
set style boxplot candles range  1.50 outliers pt 7 separation 1 labels auto unsorted
set loadpath 
set fontpath 
set psdir
set fit brief errorvariables nocovariancevariables errorscaling prescale nowrap v5
GNUTERM = "wxt"
plot sin(x)
#    EOF

【问题讨论】:

  • multiplot 是你的朋友,但没有代码,没有细节......
  • 这没有多大帮助,因为图表本身没有代码。无论如何,你需要在load"plot2.plt"周围加上引号
  • load "plot2.plt"
  • "plot1.plt" 和 "plot2.plt" 包含很多行代码。我不知道如何在不发送垃圾邮件的情况下与您分享它们。
  • 我明白,但它应该与多图一起工作,就像我的回答一样。您可能希望从一个不太复杂的代码版本开始,然后重新构建。试试引号!

标签: gnuplot insets


【解决方案1】:

好的,这里是一个通用答案,摘自 Philipp K. Janert “Gnuplot in Action”。

# functions to be plotted
f(x,a) = x<a ? sqrt(a-x) : 0       # Magnetization
g(x,b) = 0.25*x**4 + b*x**2        # Free Energy

# does the magic:
set multiplot

# the full graph
set grid
plot [-3:2.5][-1:2] f(x,0) notitle w l lw 3

# formatting the inset graphs
unset grid
unset tics
unset xtics
unset ytics
unset key
set tmargin 0; set bmargin 0; set rmargin 0; set lmargin 0
set size 0.2                      # relative size of the insets

# draw three insets, clear background, at given origins
set origin 0.175,0.425
clear
plot [-2.5:2.5][-1.5:2] g(x,-1)
set origin 0.4625,0.125
clear
plot [-2.5:2.5][-0.5:3] g(x,0)
set origin 0.675,0.425
clear
plot [-2.5:2.5][-0.5:3] g(x,1)

# cleanup
unset multiplot

产生

如果没有您的代码,必须在这里停下来,但这应该可以让您继续前进。

【讨论】:

    【解决方案2】:

    好的,

    我自己找到了答案,所以我将分享我的发现。

    在问题中,让plot2.plt 成为plot1.plt 的插入。使用任何文本编辑器打开plot2.plt,我们可以看到情节背后的代码。我们必须搜索这两个特定的行:

    set size ratio 0 1,1
    set origin 0,0
    

    因为在我的示例中,plot2.plt 是在命令 set sizeset origin 之后加载的,

    set multiplot
    
    load "plot1.plt"           # plot main figure
    
    set size 0.6, 0.5       # set size of inset
    set origin 0.4, 0.5     # move bottom left corner of inset
    load "plot2.plt"             # plot inset
    
    unset multiplot
    

    它们会覆盖预期的正确大小和比例。为了解决这个问题,我以这种方式结束了对 plot2.plt 的编辑:

    set size ratio 0 0.6,0.5    #old line: set size ratio 0 1,1
    set origin 0.4,0.5          #old line: set origin 0,0
    

    假设我们将修改后的文件保存为plot2_mod.plt。现在,为了得到正确的插图,我们可以这样写:

    set multiplot
    load "plot1.plt"           # plot main figure
    load "plot2_mod.plt"       # plot inset
    unset multiplot
    

    结果是:

    Plot with the desired inset

    显然还有一些工作要做,但这回答了问题的要点:如何使用已保存的 .plt 文件绘制插图。

    对不起,我的英语不好,我不是母语人士。请随时修正语法/拼写。

    感谢大家的帮助和建议。

    【讨论】:

    • 所以分享你的绘图代码是个好主意!显然这是由另一个提供我们无法猜到的设置的程序生成的。不管怎样,很高兴你找到了它。
    • 我在我的问题中提供了“plot1.plt”文件的代码。文件“plot2.plt”和“plot2_mod.plt”看起来非常相似。
    • 为了您未来更好的体验:(1) 一开始最好提供代码(或对它的引用)。对于想帮助你的人来说,知道胜于猜测。 (2) 可能是语言问题,但您的原始帖子并没有说这是由另一个应用程序创建的绘图的代码。那将是有用的信息。 -- 无论如何,你成功了,所以工作完成了!
    • 对不起,我是一个 PITA,但是“代码是由 gnuplot 创建的”是不对的。 Gnuplot 执行代码,它不生成代码。其他一些应用程序(八度?)可能已经创建了 gnuplot 代码。虽然对于这种情况不再重要,但准确地了解问题中的信息有助于获得好的答案。
    • 很抱歉,但是当你绘制一个情节时,你如何保存它?你不使用“保存”命令吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    相关资源
    最近更新 更多