Skip to content

Commit a75e678

Browse files
authored
Merge pull request #39 from suryabhupa/master
Add example of using gnuplot.raw() to label points in docs
2 parents 1badc6a + acaf8ef commit a75e678

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

doc/common.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,31 @@ gnuplot.axis{0,13,0,''}
9696
gnuplot.grid(true)
9797
gnuplot.title('London average temperature')
9898
```
99-
![](plot_raw.png)
99+
![](plot_raw.png)
100+
101+
We can show another example of its usage by labeling data points. Here, we generate two clusters of data with two Gaussian distributions, write it to a text file in three columns of (label, x_coor, y_coor), and plot the points with labels.
102+
103+
```lua
104+
labels_tab = {}
105+
for i=1,20 do
106+
table.insert(labels_tab, math.ceil(i/10))
107+
end
108+
x = torch.cat(torch.Tensor(10):normal(2, 0.05), torch.Tensor(10):normal(3, 0.05), 1)
109+
y = torch.cat(torch.Tensor(10):normal(2, 0.05), torch.Tensor(10):normal(3, 0.05), 1)
110+
111+
file = io.open('gaussians.txt', 'w')
112+
io.output(file)
113+
for i=1,20 do
114+
io.write(string.format('%d %f %f\n', labels_tab[i], x[i], y[i]))
115+
end
116+
io.close(file)
117+
118+
gnuplot.pngfigure('plot_labels.png')
119+
gnuplot.title('A Tale of Two Gaussians')
120+
gnuplot.raw("plot 'gaussians.txt' using 2:3:(sprintf('%d', $1)) with labels point pt 7 offset char 0.5,0.5 notitle")
121+
gnuplot.xlabel('x')
122+
gnuplot.ylabel('y')
123+
gnuplot.grid(true)
124+
gnuplot.plotflush()
125+
```
126+
![](plot_labels.png)

doc/plot_labels.png

17.4 KB
Loading

0 commit comments

Comments
 (0)