gnuplot:在一个字符串列中绘制具有基于颜色的值的点,并在图例中显示字符串 [英] gnuplot: plot points with color based values in one string column and show string in legend

查看:103
本文介绍了gnuplot:在一个字符串列中绘制具有基于颜色的值的点,并在图例中显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制分类结果并标记真实的类.因此,基本上我需要基于字符串列中的值为每个点分配颜色.

I would like to plot results of classification and mark true classes. So, basically what I need is to assign a color for each point base on value in a string column.

数据集如下:

5.1 3.5 1.4 0.2鸢尾花

5.1 3.5 1.4 0.2 Iris-setosa

我最终得到了以下解决方案的脚本(感谢此处的答案:

I ended up with script following solution (thanks to the answer in here: How to make points one color when a third column equals zero, and another color otherwise, in Gnuplot?)

set palette model RGB defined (0 "red",1 "blue", 2 "green")
plot 'iris.data' using 1:2:5 notitle with points pt 2 palette

在原始数据集中,我用数字替换了字符串标签,因为我不知道如何在gnuplot中处理字符串.有没有一种方法可以将字符串映射到颜色?

in the original dataset I replaced string labels with numbers, because I don't know how to work with strings in gnuplot. Is there a way how to map string to colors?

当前输出如下所示:

Currently the output looks like this:

但是我不喜欢渐变调色板,因为在这种情况下它没有意义.我更喜欢带有单一颜色和班级名称的普通图例.知道怎么做吗?

However I don't like the gradient palette because it doesn't make sense in this case. I would prefer normal legend with a single color and name of the class. Any idea how to do that?

推荐答案

一种方法是使用使用数据文件Data.csv:

5.4452 4.6816 blue
1.2079 9.4082 red
7.4732 6.5507 red
2.3329 8.2996 red
3.4535 2.1937 green
1.7909 2.5173 green
2.5383 7.9700 blue

和此脚本:

set pointsize 3
plot "< awk '{if($3 == \"red\") print}' Data.csv" u 1:2 t "red" w p pt 2, \
     "< awk '{if($3 == \"green\") print}' Data.csv" u 1:2 t "green" w p pt 2, \
     "< awk '{if($3 == \"blue\") print}' Data.csv" u 1:2 t "blue" w p pt 2

您得到以下情节:

awk所做的只是简单地检查数据文件的第三个参数,仅在它具有某些值(例如红色或蓝色)的情况下才打印该行.

What awk does is simply check the third parameter of the data file and only print the line if it has some value: like red or blue.

您还将摆脱带有渐变的调色板.

You would also get rid of the palette with the gradient.

可以通过使用gnuplot 迭代来进一步改进该脚本.

The script could be further improved by using gnuplot iterations.

这篇关于gnuplot:在一个字符串列中绘制具有基于颜色的值的点,并在图例中显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆