slaon的个人博客分享 http://blog.sciencenet.cn/u/slaon

博文

[转载]Gnuplot 插入png图片和pdf图片

已有 2033 次阅读 2021-5-26 10:21 |系统分类:科研笔记|文章来源:转载

本来想在Latex中的\Tikz工具箱添加多边形,

把下面的图片中的空白区域填充

图片.png

变成这样:

图片.png

但是\Tikz不太好用,画一个椭圆,再画时,坐标变了。

原因可能是:同时使用\overpic工具箱和\Tikz工具箱。


只能换成在Gnuplot中实现

首先要将原始图片导入到Gnuplot中,有两种方法:


(1)导入jpg到Gnuplot中的例子 Link

使用 plot 中的图片方法

set size ratio -1
plot

jpg image

不过导入的图片,页边距需要调整为零,布满整个幅面

set lmargin at screen 0.0
set rmargin at screen 1.0
set bmargin at screen 0.0
set tmargin at screen 1.0

把它再输出为*.eps和*.tex,再通过Latex转换为pdf

pdflatex test.tex

不过,分辨率不行。


(2)导入pdf或jpg到Gnuplot中的例子 Link

使用Gnuplot中的Label命令

但是需要导出为 *.tex 文件

set term epslatex standalone
set output "test.tex"
set label at graph 0.75,0.25 '\includegraphics[width=2cm]{plot1.pdf}'
plot x

把它再输出为*.eps和*.tex,再通过Latex转换为pdf

pdflatex test.tex


然后在Gnuplot中添加填充

使用object中的多边形功能polygon

set label  '\includegraphics{Step1.png}' at graph 0.0,0.45
set object 1 polygon from 0,0 \
to 0.000,-2.3 \
to 2.600,-2.3 \
to 152.4,0.0

set object 1 fc rgb "black" fillstyle transparent solid 0.6 noborder


上面的命令中需要找到坐标

需要在整个幅面构建坐标系

Paper_ratio=1.0
Paper_Length=6.0*Paper_ratio #pdf页面宽度,inch
Paper_Height=0.9*Paper_ratio #pdf页面高度,inch
nn=10.0
ymin=-25.4*Paper_Height #转换为mm,xchange中页面坐标原点为左上角,故加负号
ymax=0
dy=(ymax-ymin)/nn
xmin=0
xmax=25.4*Paper_Length  #转换为mm
dx=(xmax-xmin)/nn

set xrange [xmin:xmax]
set yrange [ymin:ymax]
set xtics xmin,dx,xmax
set ytics ymin,dy,ymax

set term epslatex standalone color 
set term epslatex size Paper_Length inch,Paper_Height inch
set output 'Step2.tex'
.....
set output

前提条件是页边距全为零,如上所述。

设置坐标轴的上下限为pdf的页面尺寸。

然后在xchange pdf阅读器中,

开启“显示页面大小/位置”功能

图片.png

图片.png

在pdf 页面 挪动鼠标,可以看到坐标值如下

图片.png





https://wap.sciencenet.cn/blog-531760-1288298.html

上一篇:[转载]Latex 旋转翻转(镜像)图片
下一篇:[转载]Gnuplot 定义方框 边框
收藏 IP: 114.213.245.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-2 02:54

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部