分享

Gnuplot (八) 图例

 icewater1234 2014-08-20
本文摘录于瞬间集博客:http://blog.sciencenet.cn/u/yusufma

在同一图像中包含多组数据或函数时,图例是必要的。我们这一次谈一谈图例的微调。

这次来画前 3 阶的第一类贝塞尔函数 Jn(x)。在 gnuplot 里,0 阶和 1 阶贝塞尔函数已经定义了,分别为 besj0(x) 和besj1(x),而 2 阶贝塞尔函数可以通过递推关系构造出来。下面是例子:
gnuplot> set term wxt enhanced
gnuplot> besj2(x) = besj1(x)*2/x - besj0(x)
gnuplot> set xrange [0:20]
gnuplot> set xtics 2
gnuplot> set xlabel "X"
gnuplot> set ylabel "Y"
gnuplot> set title "Bessel Functions of the First Kind"
gnuplot> set grid
gnuplot> set style line 1 lw 2 lc rgb "#F62217"
gnuplot> set style line 2 lw 2 lc rgb "#D4A017"
gnuplot> set style line 3 lw 2 lc rgb "#2B60DE"
gnuplot> plot besj0(x) ls 1 t "J_0(x)", besj1(x) ls 2 t "J_1(x)", besj2(x) ls 3 t "J_2(x)"


之前我们讲过,plot 命令后面可以跟随一些参数(例如 linewidthlinecolor 等)来改变点线风格。在上面的例子中,我们把这些参数单独拿出来放到了 set style 命令里,定义了三个 linestyle,然后在 plot 命令里再调用这些linestyle。这样子做和我们之前的做法效果上没什么不同,唯一的区别是让 plot 命令短了一些。另外,改变风格可能容易一点。

上面是默认的图例,下面让我们进行微调。
  1. 为图例加上边框
    gnuplot> set key box
    gnuplot> replot

  2. 改变图例显示位置
    gnuplot> set key center at 10,0.7
    gnuplot> replot

  3. 把图例的 title 和图线示例调换位置
    gnuplot> set key reverse
    gnuplot> replot

  4. 调整图例边框宽度 width(或高度 height
    gnuplot> set key width 1
    gnuplot> replot

  5. 调整 title 文字对齐方式(Left 或者 Right,注意首字母大写)
    gnuplot> set key Left
    gnuplot> replot

  6. 调整图例行间隔
    gnuplot> set key spacing 1.2
    gnuplot> replot

  7. 调整图线示例长度
    gnuplot> set key samplen 2
    gnuplot> replot

这些并不是 set key 的全部参数。在 gnuplot 里,如果想深入了解任何命令的详细用法,不要忘记使用 help 命令。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多