OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 "marker='.')\n", | 67 "marker='.')\n", |
68 i, i, i, series_list_[i].label.c_str()); | 68 i, i, i, series_list_[i].label.c_str()); |
69 } else if (series_list_[i].style == LINE_STEP_GRAPH) { | 69 } else if (series_list_[i].style == LINE_STEP_GRAPH) { |
70 // Draw lines from (x[0],y[0]) to (x[1],y[0]) to (x[1],y[1]) and so on | 70 // Draw lines from (x[0],y[0]) to (x[1],y[0]) to (x[1],y[1]) and so on |
71 // to illustrate the "steps". This can be expressed by duplicating all | 71 // to illustrate the "steps". This can be expressed by duplicating all |
72 // elements except the first in x and the last in y. | 72 // elements except the first in x and the last in y. |
73 printf("x%zu = [v for dup in x%zu for v in [dup, dup]]\n", i, i); | 73 printf("x%zu = [v for dup in x%zu for v in [dup, dup]]\n", i, i); |
74 printf("y%zu = [v for dup in y%zu for v in [dup, dup]]\n", i, i); | 74 printf("y%zu = [v for dup in y%zu for v in [dup, dup]]\n", i, i); |
75 printf( | 75 printf( |
76 "plt.plot(x%zu[1:], y%zu[:-1], color=rgb_colors[%zu], " | 76 "plt.plot(x%zu[1:], y%zu[:-1], color=rgb_colors[%zu], " |
77 "path_effects=[pe.Stroke(linewidth=2, foreground='black'), " | |
terelius
2017/07/04 12:22:01
Why do we need to do this at all, and why do we on
philipel
2017/07/04 12:55:10
I guess it should be configurable by whoever creat
| |
78 "pe.Normal()], " | |
77 "label=\'%s\')\n", | 79 "label=\'%s\')\n", |
78 i, i, i, series_list_[i].label.c_str()); | 80 i, i, i, series_list_[i].label.c_str()); |
79 } else if (series_list_[i].style == DOT_GRAPH) { | 81 } else if (series_list_[i].style == DOT_GRAPH) { |
80 printf( | 82 printf( |
81 "plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\', " | 83 "plt.plot(x%zu, y%zu, color=rgb_colors[%zu], label=\'%s\', " |
82 "marker='o', ls=' ')\n", | 84 "marker='o', ls=' ')\n", |
83 i, i, i, series_list_[i].label.c_str()); | 85 i, i, i, series_list_[i].label.c_str()); |
84 } else { | 86 } else { |
85 printf("raise Exception(\"Unknown graph type\")\n"); | 87 printf("raise Exception(\"Unknown graph type\")\n"); |
86 } | 88 } |
87 } | 89 } |
90 | |
91 // IntervalSeries | |
terelius
2017/07/04 12:22:01
If this represents the background, shouldn't it be
philipel
2017/07/04 12:55:10
They are always in the background.
| |
92 for (size_t i = 0; i < interval_list_.size(); i++) { | |
93 // List intervals | |
94 printf("\n# === IntervalSeries: %s ===\n", | |
95 interval_list_[i].label.c_str()); | |
96 printf("i%zu = [", i); | |
terelius
2017/07/04 12:22:01
Maybe a longer, more explicit name for the interva
philipel
2017/07/04 12:55:10
Renamed to 'ival'.
| |
97 if (interval_list_[i].intervals.size() > 0) { | |
98 printf("(%G, %G)", interval_list_[i].intervals[0].begin, | |
99 interval_list_[i].intervals[0].end); | |
100 } | |
101 for (size_t j = 1; j < interval_list_[i].intervals.size(); j++) { | |
terelius
2017/07/04 12:22:01
Maybe remove the if statement above, loop from 0 a
philipel
2017/07/04 12:55:10
This is consistent with the style above, if we wan
| |
102 printf(", (%G, %G)", interval_list_[i].intervals[j].begin, | |
103 interval_list_[i].intervals[j].end); | |
104 } | |
105 printf("]\n"); | |
106 | |
107 printf("for i in range(0, %zu):\n", interval_list_[i].intervals.size()); | |
108 if (interval_list_[i].orientation == IntervalSeries::kHorizontal) { | |
109 printf( | |
110 " plt.axhspan(i%zu[i][0], i%zu[i][1], facecolor='%s', " | |
111 "alpha=0.3)\n", | |
112 i, i, interval_list_[i].color.c_str()); | |
113 } else { | |
114 printf( | |
115 " plt.axvspan(i%zu[i][0], i%zu[i][1], facecolor='%s', " | |
116 "alpha=0.3)\n", | |
117 i, i, interval_list_[i].color.c_str()); | |
118 } | |
119 } | |
88 } | 120 } |
89 | 121 |
90 printf("plt.xlim(%f, %f)\n", xaxis_min_, xaxis_max_); | 122 printf("plt.xlim(%f, %f)\n", xaxis_min_, xaxis_max_); |
91 printf("plt.ylim(%f, %f)\n", yaxis_min_, yaxis_max_); | 123 printf("plt.ylim(%f, %f)\n", yaxis_min_, yaxis_max_); |
92 printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str()); | 124 printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str()); |
93 printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str()); | 125 printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str()); |
94 printf("plt.title(\'%s\')\n", title_.c_str()); | 126 printf("plt.title(\'%s\')\n", title_.c_str()); |
95 if (!series_list_.empty()) { | 127 if (!series_list_.empty()) { |
96 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); | 128 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); |
97 } | 129 } |
98 } | 130 } |
99 | 131 |
100 PythonPlotCollection::PythonPlotCollection() {} | 132 PythonPlotCollection::PythonPlotCollection() {} |
101 | 133 |
102 PythonPlotCollection::~PythonPlotCollection() {} | 134 PythonPlotCollection::~PythonPlotCollection() {} |
103 | 135 |
104 void PythonPlotCollection::Draw() { | 136 void PythonPlotCollection::Draw() { |
105 printf("import matplotlib.pyplot as plt\n"); | 137 printf("import matplotlib.pyplot as plt\n"); |
138 printf("import matplotlib.patheffects as pe\n"); | |
106 printf("import colorsys\n"); | 139 printf("import colorsys\n"); |
107 for (size_t i = 0; i < plots_.size(); i++) { | 140 for (size_t i = 0; i < plots_.size(); i++) { |
108 printf("plt.figure(%zu)\n", i); | 141 printf("plt.figure(%zu)\n", i); |
109 plots_[i]->Draw(); | 142 plots_[i]->Draw(); |
110 } | 143 } |
111 printf("plt.show()\n"); | 144 printf("plt.show()\n"); |
112 } | 145 } |
113 | 146 |
114 Plot* PythonPlotCollection::AppendNewPlot() { | 147 Plot* PythonPlotCollection::AppendNewPlot() { |
115 Plot* plot = new PythonPlot(); | 148 Plot* plot = new PythonPlot(); |
116 plots_.push_back(std::unique_ptr<Plot>(plot)); | 149 plots_.push_back(std::unique_ptr<Plot>(plot)); |
117 return plot; | 150 return plot; |
118 } | 151 } |
119 | 152 |
120 } // namespace plotting | 153 } // namespace plotting |
121 } // namespace webrtc | 154 } // namespace webrtc |
OLD | NEW |