【问题标题】:gnuplot: cairolatex background issuesgnuplot:cairolatex 背景问题
【发布时间】:2021-10-04 10:59:44
【问题描述】:

我在 gnuplot 中遇到 cairolatex 终端问题。

我将终端设置如下:

et terminal cairolatex eps rounded size 5,3 font ',17' standalone background "#9e9e9e"

背景在情节之外设置正确,但在情节区域内保持白色。我也尝试过“透明”来解决同样的问题。基本上,latex中包含的自动生成的文件filename-inc是不正确的。

在附图中,您可以看到投影仪幻灯片的灰色背景,其中包含使用 gnuplot 通过 cairolatex 生成的 pdf。

这让我发疯。

编辑: 这是最少的代码。

#!/usr/local/bin/gnuplot

set terminal cairolatex eps rounded size 5,3 font ',17' standalone background "#9e9e9e"

set output "graph.tex"

set xlabel "x $x$ [$\\mu$s]"
set ylabel 'Spot size $\sigma$ [\AA]'
set yrange [-1.1:1.1]

#plot
plot sin(x) notit lw 5, \
    cos(x) notit lw 50 lc rgb "#77ff0000", \
    .5*sin(.9*x) notit lw 30 lc rgb "#200000ff"

unset output

只需在配置文件上运行 gnuplot,然后是 pdflatex graph.tex

我正在通过 MacPorts 在 Mac 上使用 gnuplot 5.4 补丁 2。

谢谢。

拉多万

【问题讨论】:

  • 您能发minimal reproducible example 以便我们重现该问题吗?
  • 添加了示例。标签只是为了测试乳胶排版。请注意,使用“透明”时存在相同的问题。看来,set terminal epslatex rounded size 5,3 font ',17' standalone nobackground 有效,但它不尊重线条透明度。当使用input 而不是standalone 时,同样的问题会出现。 -- 拉多万

标签: latex gnuplot beamer


【解决方案1】:

部分解释为什么使用lc rgb "#77ff0000" 会导致问题

颜色规范rgb "#77ff0000" 是部分透明红色的正确 gnuplot ARGB 语法。原始绘图命令应按预期适用于支持透明度的所有终端类型。不幸的是,cairolatex 的eps 变体不是其中之一,因为 PostScript 语言本身不支持透明度。下面的一些图形层(在这种情况下不确定它是 cairo 还是 latex)试图通过逐位近似替换图形的该部分来模拟它,但效果很差。

解决方案是避免使用任何使用 Alpha 通道的输出的 PostScript 变体。你应该可以接受任何一个

  set term cairolatex pdf
  set term tikz

【讨论】:

  • 感谢您的解释。我认为它必须与透明度有关,因为一旦 linecolor 放弃透明度,它就可以正常工作。我不确定我为什么放弃 pdf ......我相信它在 PowerPoint 中粘贴效果不佳;每股收益做得更好。我会试试“tikz”。谢谢! --R
  • 所以set term cairolatex pdf 使用透明线。我也可以让set term tikz 工作,但它看起来很糟糕:-);非常非乳胶......无论如何,set term cairolatex pdf 完全符合我的需要。谢谢! --R
【解决方案2】:

我可以重现您的问题,但我不太明白为什么灰色背景部分被白色覆盖......无论如何,有一个解决方法:而不是摆弄cairolatexbackground 选项,您可以放置具有所需颜色的矩形:

set object rectangle from screen 0,0 to screen 1,1 behind fc "#9e9e9e"

令人惊讶的是,这又产生了另一个问题:由于某种原因,tic 标签被隐藏了。为了更正这一点,必须指定set tics front

因为你是通过pdflatex运行输出,所以应该不需要创建eps,但是可以直接用pdf代替。因此,完整的代码是:

reset session

set terminal cairolatex rounded size 5,3 font ',17' standalone 
set output "graph.tex"

set xlabel "x $x$ [$\\mu$s]"
set ylabel 'Spot size $\sigma$ [\AA]'
set yrange [-1.1:1.1]
set tics front

set object 1 rectangle from screen 0,0 to screen 1,1 behind fc "#9e9e9e"

#plot
plot sin(x) notit lw 5, \
    cos(x) notit lw 50 lc rgb "#77ff0000", \
    .5*sin(.9*x) notit lw 30 lc rgb "#200000ff"

unset out

【讨论】:

    【解决方案3】:

    设置lc 似乎会导致白色矩形。如果检查 eps,所有具有这种线条颜色的曲线都包含为像素化图像而不是矢量图像。

    你可以像这样解决这个问题:

    #!/usr/local/bin/gnuplot
    
    set terminal cairolatex eps rounded size 5,3 font ',17' standalone background "#9e9e9e"
    
    set output "graph.tex"
    
    set xlabel "x $x$ [$\\mu$s]"
    set ylabel 'Spot size $\sigma$ [\AA]'
    set yrange [-1.1:1.1]
    
    #plot
    plot cos(x) notit lw 50 lt 7 , \
         sin(x) notit lw 5 lt 1, \
         .5*sin(.9*x) notit lw 30 lt 14
    
    unset output
    

    【讨论】:

    • 谢谢。当前的解决方法,因为目前透明度并不重要。我希望使用它,但是我可以使用下面 Eldrar 提出的脏矩形技巧......或者set term cairolatex pdf 可能会工作......或者set term tikz。所有伟大的建议。我会回来的 ... :-)。 --R
    • @RadovanUrban 不客气!另一种可能性:放弃 gnuplot 并直接在 pgfplots 中绘制曲线 :)
    • pgfplots 看起来很有趣。我想还有更多要学习的东西......它在哪里结束?! :-) -- R
    • @RadovanUrban pgfplots 很好——你可以做一些花哨的事情,比如使用投影仪叠加层来一张一张地发现你的曲线等。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多