From fca479aa63286bfac911e830676734bb2d0e845d Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Mon, 27 Apr 2020 21:41:29 +0000 Subject: [PATCH] ex-3: implement variable bins in the plot --- ex-3/main.c | 5 +++++ ex-3/plot.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ex-3/main.c b/ex-3/main.c index 67bd16a..3b7948f 100644 --- a/ex-3/main.c +++ b/ex-3/main.c @@ -100,6 +100,11 @@ int main(int argc, char **argv) { // print histogram to stdout if (opts.show_hist || opts.only_hist) { fputs("\n# histogram\n", stderr); + /* Print the bins on the first line: + * this is needed by plot.py to make a + * 2D histogram plot. + */ + fprintf(stdout, "%ld %ld\n", opts.bins_theta, opts.bins_phi); gsl_histogram2d_fprintf(stdout, hist, "%g", "%g"); } diff --git a/ex-3/plot.py b/ex-3/plot.py index a67c754..a610246 100755 --- a/ex-3/plot.py +++ b/ex-3/plot.py @@ -5,8 +5,8 @@ from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import sys +bins = tuple(map(int, sys.stdin.readline().split())) xedges, yedges, counts = loadtxt(sys.stdin, unpack=True, usecols=[0,2,4]) -bins = (30, 60) counts = counts.reshape(bins) plt.rcParams['font.size'] = 15