zoukankan      html  css  js  c++  java
  • Scilab 的画图函数(3)

    我们在做数据画图或函数图像时常常须要使用对数坐标系。尤其是数据的范围跨越非常多个数量级时。通常的线性坐标系下无法表现出数据特征。

     Scilab Plot函数无法画出对数坐标。须要使用 plot2d 函数。

     plot2d 函数的基本使用方法例如以下:

    plot2d([logflag,][x,],y[,style[,strf[,leg[,rect[,nax]]]]])

    plot2d([logflag,][x,],y,<opt_args>)

     

    以下是一个简单的样例:

    iter = linspace(0,10,11);
    err = 10.^(-iter);
    plot2d("nl", iter, err, style=2);
    set(gca(),"grid",[1 1]);

    这个样例假设在普通的坐标系下看,是这个样子的:

    plot(iter,err);
    set(gca(),"grid",[1 1]);

    因为数据非常快就非常接近0了。在图中非常难看出后面的趋势。

    以下来具体的解说一下plot2d函数。

    plot2d("nl", iter, err, style=2);

     “nl” 表示,横坐标为正常的模式(normal,纵坐标为对数(log.

    Style = 2 表示的是曲线的颜色。表示的是colormap 中的第二项,也就是蓝色。

    假设是负数。则表示用不同的线型。假设既要设置曲线的颜色,又要设置线型,那么。

    。。临时还没搞定。

    以下再给一个样例,通过rect參数控制xy的范围:

    x=[0:0.1:2*%pi]';
    plot2d(x,[sin(x) sin(2*x) sin(3*x)],rect=[0,0,6,0.5]);

    有点跑题了,接着介绍对数坐标系画图。

    以下再给一个样例:

    ind = linspace(0,6,7);
    iter = 10.^ind;
    err1 = 10.^(-ind);
    err2 = (10.^(-ind)).^2;
    xset("font size", 4);  
    plot2d("ll", iter, err1, style=2);
    plot2d("ll", iter, err2, style=3);
    title("Loglog","fontsize", 4);
    xlabel("Iterations","fontsize", 4);
    ylabel("Error","fontsize", 4);
    set(gca(),"grid",[5 5]);
    legend(['error1';'error2'],"in_lower_left");

    这个图是双对数坐标,同一时候还调整了图上的文字。须要注意的是:

    xset("font size", 4);  

    语句一定要在

    legend(['error1';'error2'],"in_lower_left");

    语句之前调用。否则得到的图形的legend 的字号会有问题,以下是个实验,先运行例如以下语句:

    ind = linspace(0,6,7);
    iter = 10.^ind;
    err1 = 10.^(-ind);
    err2 = (10.^(-ind)).^2;
    plot2d("ll", iter, err1, style=2);
    plot2d("ll", iter, err2, style=3);
    title("Loglog","fontsize", 4);
    xlabel("Iterations","fontsize", 4);
    ylabel("Error","fontsize", 4);
    set(gca(),"grid",[5 5]);
    legend(['error1';'error2'],"in_lower_left");

    这个图形是和我们的预期一样的。标题和Label的字号变大了,刻度和Legend的字号还是原来的大小。

    接着运行:

    xset("font size", 4);

    结果是刻度上的字号更新为正确的大小了,可legend 的字号没变。看来这个是 scilab 的一个bug

    所以我们须要先设置字号。然后调用legend 函数。



  • 相关阅读:
    protobuf配置与使用
    gvim配置
    html div+css做页面布局
    php info
    开源相关工具汇总
    mem 0908
    linux dd指令
    java面试(2)--大数据相关
    Java基础面试题(1)
    转自ruby迷: 使用Net::SSH和Net::SCP编写Linux服务器管理脚本
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7284427.html
Copyright © 2011-2022 走看看