Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to plot points in color in Gnuplot

📅 2015-Jun-19 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ colors, gnuplot ⬩ 📚 Archive

Points plotted with color in Gnuplot

I had some 2D data in a file in the following format:

6.37026 2.42441 0
4.16001 6.55597 2
3.54946 7.15539 2
4.35229 3.8448 1
7.12706 1.2563 3
1.98478 8.68739 0
7.67213 2.22039 0
3.85744 7.3549 1

Each data point is on a separate line. The first and second columns were the X and Y coordinates of the data. The third column represents that which of the 4 classes (0-3) that points belonged to.

To understand the data better, I wanted to visualize it by drawing a 2D plot with a point for each data point. To distinguish the points belonging to different classes, I wanted points of each class to be drawn with a distinct color.

Once your data is in this format, achieving the above is easy in Gnuplot:

plot("sales_data.txt") with points palette

Tried with: Gnuplot 5.0 and Ubuntu 14.04


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧