13 #include "gnuplot-iostream.h" 15 #include "../JASPL/jTypeTraits/jtypetraits.h" 19 template <
typename T >
22 typedef std::pair< T, std::string > series_pair;
27 "Can only plot container-like objects.");
28 static_assert(std::is_arithmetic< typename T::value_type >::value,
29 "Can only plot arithmetic types.");
38 void SetXAxisLabel( std::string x_label ) {
42 void SetYAxisLabel( std::string y_label ) {
46 void SetSavePath( std::string file_path ) {
50 void AddSeries( T series, std::string title ) {
51 series_list.push_back( series_pair( series, title ) );
54 void SetMaxNumPoints( uint max_points ) {
60 T decimate(
const T& series, uint desired_points ) {
61 uint pivot =
static_cast<uint
> (series.size() / desired_points);
63 std::vector<uint> pivot_indices;
65 for( uint i = 0 ; i < series.size() ; i ++ ) {
67 pivot_indices.push_back(i);
73 for (
const auto& idx : pivot_indices ) {
74 y_vals.push_back( series.at(idx) );
78 std::string save_file_path;
83 std::list< series_pair > series_list;
87 template <
typename T>
void plot( T signal ) {
90 "Can only plot container-like objects.");
91 static_assert(std::is_arithmetic< typename T::value_type >::value,
92 "Can only plot arithmetic types.");
96 gp <<
"plot '-' with lines notitle\n";
100 template <
class T>
void plot ( T signal, uint num_plot_points ) {
103 "Can only plot container-like objects.");
104 static_assert(std::is_arithmetic< typename T::value_type >::value,
105 "Can only plot arithmetic types.");
109 uint pivot =
static_cast<uint
> (signal.size() / num_plot_points);
111 std::vector<uint> pivot_indices;
113 for( uint i = 0 ; i < signal.size() ; i ++ ) {
114 if ( i%pivot == 0 ) {
115 pivot_indices.push_back(i);
121 for (
const auto& idx : pivot_indices ) {
122 y_vals.push_back( signal.at(idx) );
125 gp <<
"plot '-' with lines notitle\n";
131 template <
class T>
void plot ( T& signal, std::string plot_title ) {
134 "Can only plot container-like objects.");
135 static_assert(std::is_arithmetic< typename T::value_type >::value,
136 "Can only plot arithmetic types.");
140 gp <<
"set title '"+plot_title+
"'\n";
141 gp <<
"plot '-' with lines notitle\n";
146 void plot_to_disk ( T& signal_a,
147 std::string signal_a_title,
148 std::string x_axis_label,
149 std::string y_axis_label,
150 std::string plot_title,
151 std::string save_file_path ) {
154 "Can only plot container-like objects.");
155 static_assert(std::is_arithmetic< typename T::value_type >::value,
156 "Can only plot arithmetic types.");
160 std::string out_file_path = save_file_path + plot_title +
".png";
162 gp <<
"set term png transparent truecolor size 1280,720\n";
163 gp <<
" set border lw 3 lc rgb 'yellow' " << std::endl;
164 gp <<
" set key font ', 20' textcolor rgb 'yellow' " << std::endl;
165 gp <<
"set output '"+out_file_path+
"'\n";
166 gp <<
"set xlabel font ', 20' " << std::endl;
167 gp <<
"set ylabel font ', 20' " << std::endl;
168 gp <<
"set xlabel '" + x_axis_label +
"' tc rgb 'yellow' " << std::endl;
169 gp <<
"set ylabel '" + y_axis_label +
"' tc rgb 'yellow' " << std::endl;
170 gp <<
"set xtics font ', 20' tc rgb 'yellow'" << std::endl;
171 gp <<
"set ytics font ', 20' tc rgb 'yellow'" << std::endl;
172 gp <<
"set title '"+plot_title+
"' font 'arial,30' tc rgb 'yellow' \n";
173 gp <<
"plot" << gp.file1d( signal_a ) <<
"with lines linewidth 5 title '" + signal_a_title +
"'" << std::endl;
178 void plot_to_disk ( T& signal_a,
180 std::string signal_a_title,
181 std::string signal_b_title,
182 std::string x_axis_label,
183 std::string y_axis_label,
184 std::string plot_title,
185 std::string save_file_path ) {
188 "Can only plot container-like objects.");
189 static_assert(std::is_arithmetic< typename T::value_type >::value,
190 "Can only plot arithmetic types.");
194 std::string out_file_path = save_file_path + plot_title +
".png";
196 gp <<
"set term png transparent truecolor size 1280,720\n";
197 gp <<
" set border lw 3 lc rgb 'yellow' " << std::endl;
198 gp <<
" set key font ', 20' textcolor rgb 'yellow' " << std::endl;
199 gp <<
"set output '"+out_file_path+
"'\n";
200 gp <<
"set xlabel font ', 20' " << std::endl;
201 gp <<
"set ylabel font ', 20' " << std::endl;
202 gp <<
"set xlabel '" + x_axis_label +
"' tc rgb 'yellow' " << std::endl;
203 gp <<
"set ylabel '" + y_axis_label +
"' tc rgb 'yellow' " << std::endl;
204 gp <<
"set xtics font ', 20' tc rgb 'yellow'" << std::endl;
205 gp <<
"set ytics font ', 20' tc rgb 'yellow'" << std::endl;
206 gp <<
"set title '"+plot_title+
"' font 'arial,30' tc rgb 'yellow' \n";
207 gp <<
"plot" << gp.file1d( signal_a ) <<
"with lines linewidth 5 title '" + signal_a_title +
"',";
208 gp << gp.file1d( signal_b ) <<
"with lines linewidth 5 title '" + signal_b_title +
"'" << std::endl;
213 template <
class T>
void plot ( T& signal, std::string plot_title, uint num_plot_points ) {
216 "Can only plot container-like objects.");
217 static_assert(std::is_arithmetic< typename T::value_type >::value,
218 "Can only plot arithmetic types.");
222 uint pivot =
static_cast<uint
> (signal.size() / num_plot_points);
224 std::vector<uint> pivot_indices;
226 for( uint i = 0 ; i < signal.size() ; i ++ ) {
227 if ( i%pivot == 0 ) {
228 pivot_indices.push_back(i);
234 for (
const auto& idx : pivot_indices ) {
235 y_vals.push_back( signal.at(idx) );
238 gp <<
"set title '"+plot_title+
"'\n";
239 gp <<
"plot '-' with lines notitle\n";