开发者

How do I indicate labels with different point types in Gnuplot?

开发者 https://www.devze.com 2023-02-09 23:32 出处:网络
Let\'s say I have data I\'d like to be plotted in a file \"animals.txt\": cat 5.2 1.0 cat 5.4 1.3 cat 5.2 1.2

Let's say I have data I'd like to be plotted in a file "animals.txt":

cat 5.2 1.0
cat 5.4 1.3
cat 5.2 1.2
dog 3.8 1.1
dog 3.5 1.5
dog 3.6 1.3
giraffe 1.3 9.7
giraffe 1.5 9.0
giraffe 1.4 9.9

I can generate a scatter plot with labels using:

plot "animals.txt" u 2:3:1 w labels

I can also vary the style of each point using something like:

plot "animals.txt" u 2:3 w points pointtype 3

Instead of using labels (which might overlap), is it possible to have the points use different point types or colors for each category? (For instance, "cat" would be in red using pointtype 3, "dog" would be in blue using pointtype 4, etc.)

I could use "lc variable" and replace the labels column with c开发者_JS百科olors, but the file I'm working with has too many different labels for me to do that easily.


I don't think there is a way to do this directly.

However, an easy fix is to use gnuplot's interface to awk. You can then plot 3 separate graphs, one for each animal.

plot "<awk '{ if($1 == \"cat\") print $2,$3  }' animals.dat" u 1:2 w points title "cat", \
     "<awk '{ if($1 == \"dog\") print $2,$3  }' animals.dat" u 1:2 w points title "dog", \
     "<awk '{ if($1 == \"giraffe\") print $2,$3  }' animals.dat" u 1:2 w points title "giraffe"

Since the only difference between each line is the name of the animal, you could probably script this in a better way, but you get the idea,

Tom

0

精彩评论

暂无评论...
验证码 换一张
取 消