【问题标题】:Gnuplot: plotting points with color based iris dataGnuplot:使用基于颜色的虹膜数据绘制点
【发布时间】:2015-05-18 05:57:35
【问题描述】:

我有这个虹膜数据...

5.1     3.5     1.4     0.2     Iris-setosa
4.9     3       1.4     0.2     Iris-setosa
7       3.2     4.7     1.4     Iris-versicolor
6.4     3.2     4.5     1.5     Iris-versicolor
7.1     3       5.9     2.1     Iris-virginica
6.3     2.9     5.6     1.8     Iris-virginica
.
.
.

我使用 gnuplot (plot 'c:\iris.data') 得到了图表

但我想要第 5 列颜色组的点(iris-setosa、iris-versicolor、iris-virginica)

例如。 . .

iris-setosa = 红色, iris-versicolor= 绿色, iris-virginica = 蓝色

如何获得彩色图?

请回答。 . . .

【问题讨论】:

    标签: gnuplot classification svm libsvm


    【解决方案1】:

    用数字索引替换你的颜色,例如,像这样:

    5.1     3.5     1.4     0.2     0
    4.9     3       1.4     0.2     0
    7       3.2     4.7     1.4     1
    6.4     3.2     4.5     1.5     1
    7.1     3       5.9     2.1     2
    6.3     2.9     5.6     1.8     2
    

    一个简单的搜索和替换脚本应该可以为您做到这一点。

    然后你可以使用 Gnuplot 的linecolor palette,例如如下:

    plot "iris.data" u 1:2:5 w p lc palette
    

    要像这样调整使用的颜色:

    set palette defined (0 "red", 1 "green", 2 "blue")
    

    请注意,虽然我在这里选择使用确切的索引,但调色板定义是相对的,我不妨使用:

    set palette defined (-11 "red", -2 "green", 7 "blue")
    

    【讨论】:

      【解决方案2】:

      如果您想将字符串值保留在数据文件中,您可以使用 gnuplot 提供的少数字符串函数构建某种查找表(类似的用例请参见 Different coloured bars in gnuplot bar chart?):

      IrisColors = 'Iris-setosa Iris-versicolor Iris-virginica'
      index(s) = words(substr(IrisColors, 0, strstrt(IrisColors, s)-1)) + 1
      
      set style fill solid noborder
      set linetype 1 lc rgb 'red'
      set linetype 2 lc rgb 'green'
      set linetype 3 lc rgb 'blue'
      
      plot 'iris.data' using 1:2:(index(strcol(5))) linecolor variable
      

      请注意,字符串比较区分大小写,并且不能将带有空格的字符串用作单个键。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-14
        • 2021-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-05
        • 2021-04-02
        • 1970-01-01
        相关资源
        最近更新 更多