1515
1616namespace {
1717
18- std::string gp_escape (const std::string& text) {
19- std::string out;
20- out.reserve (text.size ());
21- for (char c : text) {
22- if (c == ' \' ' ) {
23- out += " ''" ;
24- } else {
25- out += c;
26- }
27- }
28- return out;
29- }
30-
31- void apply_large_typography (gnuplotpp::AxesSpec& ax,
32- const double label_pt = 17.0 ,
33- const double title_pt = 20.0 ) {
34- std::vector<std::string> commands;
35- if (!ax.xlabel .empty ()) {
36- commands.push_back (" set xlabel '" + gp_escape (ax.xlabel ) + " ' font 'Helvetica," +
37- std::to_string (label_pt) + " '" );
38- }
39- if (!ax.ylabel .empty ()) {
40- commands.push_back (" set ylabel '" + gp_escape (ax.ylabel ) + " ' font 'Helvetica," +
41- std::to_string (label_pt) + " '" );
42- }
43- if (!ax.y2label .empty ()) {
44- commands.push_back (" set y2label '" + gp_escape (ax.y2label ) + " ' font 'Helvetica," +
45- std::to_string (label_pt) + " '" );
46- }
47- if (!ax.title .empty ()) {
48- commands.push_back (" set title '{/:Bold " + gp_escape (ax.title ) + " }' font 'Helvetica," +
49- std::to_string (title_pt) + " '" );
50- }
51- ax.gnuplot_commands .insert (ax.gnuplot_commands .end (), commands.begin (), commands.end ());
52- }
53-
5418gnuplotpp::FigureSpec make_spec (const std::string& title) {
5519 using namespace gnuplotpp ;
5620 FigureSpec fs;
@@ -61,12 +25,6 @@ gnuplotpp::FigureSpec make_spec(const std::string& title) {
6125 fs.title = title;
6226 fs.text_mode = TextMode::Enhanced;
6327 fs.formats = {OutputFormat::Pdf, OutputFormat::Png, OutputFormat::Svg};
64- fs.palette = ColorPalette::Grayscale;
65- fs.style .font = " Helvetica" ;
66- fs.style .font_pt = 13.5 ;
67- fs.style .line_width_pt = 1.8 ;
68- fs.style .point_size = 0.85 ;
69- fs.style .grid = false ;
7028 fs.font_fallbacks = {" Arial" , " Nimbus Sans" , " DejaVu Sans" , " Helvetica" };
7129 fs.panel_labels = false ;
7230 fs.caption .clear ();
@@ -127,7 +85,6 @@ int main(int argc, char** argv) {
12785 ax.xtick_step = 1.0 ;
12886 ax.has_ytick_step = true ;
12987 ax.ytick_step = 1.0 ;
130- apply_large_typography (ax);
13188 fig.axes (0 ).set (ax);
13289
13390 std::vector<double > q_theory, q_sample;
@@ -184,7 +141,6 @@ int main(int argc, char** argv) {
184141 ax.ymax = 3.2 ;
185142 ax.has_xtick_step = true ;
186143 ax.xtick_step = 0.25 ;
187- apply_large_typography (ax);
188144 fig.axes (0 ).set (ax);
189145
190146 std::vector<double > y_grid, half_w;
@@ -217,7 +173,6 @@ int main(int argc, char** argv) {
217173 std::to_string (summary.median ) + " nohead lw 2.0 lc rgb '#1f1f1f' front" ,
218174 " set arrow 22 from -0.30," + std::to_string (summary.q3 ) + " to 0.30," +
219175 std::to_string (summary.q3 ) + " nohead lw 1.5 lc rgb '#1f1f1f' dt 2 front" };
220- apply_large_typography (ax);
221176 fig.axes (0 ).set (ax);
222177
223178 fig.axes (0 ).add_series (SeriesSpec{.label = " left" ,
@@ -271,7 +226,6 @@ int main(int argc, char** argv) {
271226 ax.xmax = 1.3 ;
272227 ax.has_xtick_step = true ;
273228 ax.xtick_step = 0.1 ;
274- apply_large_typography (ax);
275229 fig.axes (0 ).set (ax);
276230
277231 const auto box = box_summary (samples);
@@ -281,7 +235,6 @@ int main(int argc, char** argv) {
281235 ax.ymin = *smin_it - ypad;
282236 ax.ymax = *smax_it + ypad;
283237 ax.gnuplot_commands = {" set xtics ('Sample A' 1.0) font 'Helvetica,13'" };
284- apply_large_typography (ax);
285238 fig.axes (0 ).set (ax);
286239
287240 std::vector<double > x_pts;
@@ -317,7 +270,6 @@ int main(int argc, char** argv) {
317270 std::to_string (box.whisker_low ) + " nohead lw 1.5 lc rgb '#1f1f1f'" ,
318271 " set arrow 5 from 0.95," + std::to_string (box.whisker_high ) + " to 1.05," +
319272 std::to_string (box.whisker_high ) + " nohead lw 1.5 lc rgb '#1f1f1f'" };
320- apply_large_typography (ax);
321273 fig.axes (0 ).set (ax);
322274
323275 if (render (fig, out_root / " box_summary" / " figures" ) != 0 ) return 1 ;
@@ -328,7 +280,7 @@ int main(int argc, char** argv) {
328280 auto fs = make_spec (" Confidence Ellipse" );
329281 Figure fig (fs);
330282 AxesSpec ax;
331- ax.title = " 2 -Sigma Confidence Ellipse " ;
283+ ax.title = " 1/2/3 -Sigma Confidence Ellipses " ;
332284 ax.xlabel = " x" ;
333285 ax.ylabel = " y" ;
334286 ax.grid = true ;
@@ -338,7 +290,6 @@ int main(int argc, char** argv) {
338290 ax.legend_spec .opaque = true ;
339291 ax.legend_spec .has_font_pt = true ;
340292 ax.legend_spec .font_pt = 13.0 ;
341- apply_large_typography (ax);
342293 fig.axes (0 ).set (ax);
343294
344295 std::normal_distribution<double > nx (0.0 , 1.0 );
@@ -359,16 +310,36 @@ int main(int argc, char** argv) {
359310 x,
360311 y);
361312
362- std::vector<double > ex, ey;
363- confidence_ellipse (x, y, 2.0 , ex, ey, 240 );
313+ std::vector<double > ex1, ey1;
314+ std::vector<double > ex2, ey2;
315+ std::vector<double > ex3, ey3;
316+ confidence_ellipse (x, y, 1.0 , ex1, ey1, 240 );
317+ confidence_ellipse (x, y, 2.0 , ex2, ey2, 240 );
318+ confidence_ellipse (x, y, 3.0 , ex3, ey3, 240 );
319+ fig.axes (0 ).add_series (
320+ SeriesSpec{.label = " 1{/Symbol s} ellipse" ,
321+ .has_line_width = true ,
322+ .line_width_pt = 2.0 ,
323+ .has_color = true ,
324+ .color = " #1f77b4" },
325+ ex1,
326+ ey1);
364327 fig.axes (0 ).add_series (
365328 SeriesSpec{.label = " 2{/Symbol s} ellipse" ,
366329 .has_line_width = true ,
367330 .line_width_pt = 2.8 ,
368331 .has_color = true ,
369332 .color = " #e45756" },
370- ex,
371- ey);
333+ ex2,
334+ ey2);
335+ fig.axes (0 ).add_series (
336+ SeriesSpec{.label = " 3{/Symbol s} ellipse" ,
337+ .has_line_width = true ,
338+ .line_width_pt = 2.0 ,
339+ .has_color = true ,
340+ .color = " #2ca02c" },
341+ ex3,
342+ ey3);
372343
373344 if (render (fig, out_root / " confidence_ellipse" / " figures" ) != 0 ) return 1 ;
374345 }
@@ -398,7 +369,6 @@ int main(int argc, char** argv) {
398369 ax.xtick_step = 10.0 ;
399370 ax.has_ytick_step = true ;
400371 ax.ytick_step = 0.2 ;
401- apply_large_typography (ax);
402372 fig.axes (0 ).set (ax);
403373
404374 std::vector<double > sig (800 );
0 commit comments