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'), " |
| 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()); |
| 86 } else if (series_list_[i].style == VSPAN_GRAPH) { |
| 87 printf("for i in range(0, %zu, 2):\n", series_list_[i].points.size()); |
| 88 printf(" plt.axvspan(x%zu[i], x%zu[i+1], facecolor='%s', alpha=0.3)\n", |
| 89 i, i, series_list_[i].color.c_str()); |
84 } else { | 90 } else { |
85 printf("raise Exception(\"Unknown graph type\")\n"); | 91 printf("raise Exception(\"Unknown graph type\")\n"); |
86 } | 92 } |
87 } | 93 } |
88 } | 94 } |
89 | 95 |
90 printf("plt.xlim(%f, %f)\n", xaxis_min_, xaxis_max_); | 96 printf("plt.xlim(%f, %f)\n", xaxis_min_, xaxis_max_); |
91 printf("plt.ylim(%f, %f)\n", yaxis_min_, yaxis_max_); | 97 printf("plt.ylim(%f, %f)\n", yaxis_min_, yaxis_max_); |
92 printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str()); | 98 printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str()); |
93 printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str()); | 99 printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str()); |
94 printf("plt.title(\'%s\')\n", title_.c_str()); | 100 printf("plt.title(\'%s\')\n", title_.c_str()); |
95 if (!series_list_.empty()) { | 101 if (!series_list_.empty()) { |
96 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); | 102 printf("plt.legend(loc=\'best\', fontsize=\'small\')\n"); |
97 } | 103 } |
98 } | 104 } |
99 | 105 |
100 PythonPlotCollection::PythonPlotCollection() {} | 106 PythonPlotCollection::PythonPlotCollection() {} |
101 | 107 |
102 PythonPlotCollection::~PythonPlotCollection() {} | 108 PythonPlotCollection::~PythonPlotCollection() {} |
103 | 109 |
104 void PythonPlotCollection::Draw() { | 110 void PythonPlotCollection::Draw() { |
105 printf("import matplotlib.pyplot as plt\n"); | 111 printf("import matplotlib.pyplot as plt\n"); |
| 112 printf("import matplotlib.patheffects as pe\n"); |
106 printf("import colorsys\n"); | 113 printf("import colorsys\n"); |
107 for (size_t i = 0; i < plots_.size(); i++) { | 114 for (size_t i = 0; i < plots_.size(); i++) { |
108 printf("plt.figure(%zu)\n", i); | 115 printf("plt.figure(%zu)\n", i); |
109 plots_[i]->Draw(); | 116 plots_[i]->Draw(); |
110 } | 117 } |
111 printf("plt.show()\n"); | 118 printf("plt.show()\n"); |
112 } | 119 } |
113 | 120 |
114 Plot* PythonPlotCollection::AppendNewPlot() { | 121 Plot* PythonPlotCollection::AppendNewPlot() { |
115 Plot* plot = new PythonPlot(); | 122 Plot* plot = new PythonPlot(); |
116 plots_.push_back(std::unique_ptr<Plot>(plot)); | 123 plots_.push_back(std::unique_ptr<Plot>(plot)); |
117 return plot; | 124 return plot; |
118 } | 125 } |
119 | 126 |
120 } // namespace plotting | 127 } // namespace plotting |
121 } // namespace webrtc | 128 } // namespace webrtc |
OLD | NEW |