From acaf8ef3e67a18b96a7acdb238ac0dd456ad8b37 Mon Sep 17 00:00:00 2001 From: Surya Bhupatiraju Date: Thu, 8 Dec 2016 00:24:47 +0000 Subject: Add example of using gnuplot.raw() to label points in docs --- doc/common.md | 29 ++++++++++++++++++++++++++++- doc/plot_labels.png | Bin 0 -> 17849 bytes 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 doc/plot_labels.png diff --git a/doc/common.md b/doc/common.md index b63801d..7ee2c63 100644 --- a/doc/common.md +++ b/doc/common.md @@ -96,4 +96,31 @@ gnuplot.axis{0,13,0,''} gnuplot.grid(true) gnuplot.title('London average temperature') ``` -![](plot_raw.png) +![](plot_raw.png) + +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. + +```lua +labels_tab = {} +for i=1,20 do + table.insert(labels_tab, math.ceil(i/10)) +end +x = torch.cat(torch.Tensor(10):normal(2, 0.05), torch.Tensor(10):normal(3, 0.05), 1) +y = torch.cat(torch.Tensor(10):normal(2, 0.05), torch.Tensor(10):normal(3, 0.05), 1) + +file = io.open('gaussians.txt', 'w') +io.output(file) +for i=1,20 do + io.write(string.format('%d %f %f\n', labels_tab[i], x[i], y[i])) +end +io.close(file) + +gnuplot.pngfigure('plot_labels.png') +gnuplot.title('A Tale of Two Gaussians') +gnuplot.raw("plot 'gaussians.txt' using 2:3:(sprintf('%d', $1)) with labels point pt 7 offset char 0.5,0.5 notitle") +gnuplot.xlabel('x') +gnuplot.ylabel('y') +gnuplot.grid(true) +gnuplot.plotflush() +``` +![](plot_labels.png) diff --git a/doc/plot_labels.png b/doc/plot_labels.png new file mode 100644 index 0000000..5687174 Binary files /dev/null and b/doc/plot_labels.png differ -- cgit v1.2.3