| 108 | == Simple 2D Example == |
| 109 | |
| 110 | === Note: Because one of this week's tasks is to make sane defaults, the sample program here will likely be shorter === |
| 111 | |
| 112 | {{{ |
| 113 | #!cpp |
| 114 | multimap<double, double> data; |
| 115 | |
| 116 | svg_2d_plot my_plot; |
| 117 | |
| 118 | for(double i=0; i<10; ++i) |
| 119 | { |
| 120 | data.insert(std::pair<double,double>(i,f(i))); |
| 121 | } |
| 122 | |
| 123 | // size/scale settings |
| 124 | my_plot.set_image_size(500, 350) |
| 125 | .set_x_scale(-1, 10) |
| 126 | .set_y_scale(-1, 5); |
| 127 | |
| 128 | // Text settings |
| 129 | my_plot.set_title("2D Graph Test") |
| 130 | .set_title_font_size(29); |
| 131 | |
| 132 | // command settings |
| 133 | my_plot.set_axis(true) |
| 134 | .set_legend(true) |
| 135 | .set_plot_window(true) |
| 136 | .set_x_major_labels(true) |
| 137 | .set_y_major_labels(true); |
| 138 | |
| 139 | // color settings |
| 140 | my_plot.set_background_color(darkgray) |
| 141 | .set_legend_background_color(white) |
| 142 | .set_plot_background_color(white); |
| 143 | |
| 144 | //axis settings |
| 145 | my_plot.set_x_major_tick(2) |
| 146 | .set_x_num_minor_ticks(1) |
| 147 | .set_x_major_tick_length(14) |
| 148 | .set_x_minor_tick_length(7) |
| 149 | .set_x_major_tick_width(2) |
| 150 | .set_x_minor_tick_width(1) |
| 151 | |
| 152 | .set_y_major_tick(2) |
| 153 | .set_y_num_minor_ticks(1) |
| 154 | .set_y_major_tick_length(20) |
| 155 | .set_y_minor_tick_length(10) |
| 156 | .set_y_major_tick_width(2) |
| 157 | .set_y_minor_tick_width(1); |
| 158 | |
| 159 | //legend settings |
| 160 | my_plot.set_legend_title_font_size(15); |
| 161 | |
| 162 | plot_range(my_plot, data.begin(), data.end(), "sqrt(x)", black); |
| 163 | |
| 164 | my_plot.write("D:/test.svg"); |
| 165 | }}} |
| 166 | |
| 167 | Produces the following file: [http://www.tcnj.edu/~voytko2/svg_2d.htm] |
| 168 | |