diff --git a/rtc_tools/event_log_visualizer/plot_base.cc b/rtc_tools/event_log_visualizer/plot_base.cc index 8313beb98d..2308144522 100644 --- a/rtc_tools/event_log_visualizer/plot_base.cc +++ b/rtc_tools/event_log_visualizer/plot_base.cc @@ -66,6 +66,11 @@ void Plot::SetSuggestedYAxis(float min_value, SetYAxis(min_value, max_value, label, bottom_margin, top_margin); } +void Plot::SetYAxisTickLabels( + const std::vector>& labels) { + yaxis_tick_labels_ = labels; +} + void Plot::SetTitle(const std::string& title) { title_ = title; } diff --git a/rtc_tools/event_log_visualizer/plot_base.h b/rtc_tools/event_log_visualizer/plot_base.h index 72fa575ea6..bd6d653f91 100644 --- a/rtc_tools/event_log_visualizer/plot_base.h +++ b/rtc_tools/event_log_visualizer/plot_base.h @@ -137,6 +137,9 @@ class Plot { float bottom_margin = 0, float top_margin = 0); + void SetYAxisTickLabels( + const std::vector>& labels); + // Sets the title of the plot. void SetTitle(const std::string& title); @@ -162,6 +165,7 @@ class Plot { float yaxis_min_; float yaxis_max_; std::string yaxis_label_; + std::vector> yaxis_tick_labels_; std::string title_; std::string id_; std::vector series_list_; diff --git a/rtc_tools/event_log_visualizer/plot_protobuf.cc b/rtc_tools/event_log_visualizer/plot_protobuf.cc index 3b2842d877..9b05093554 100644 --- a/rtc_tools/event_log_visualizer/plot_protobuf.cc +++ b/rtc_tools/event_log_visualizer/plot_protobuf.cc @@ -60,6 +60,12 @@ void ProtobufPlot::ExportProtobuf(webrtc::analytics::Chart* chart) { chart->set_yaxis_label(yaxis_label_); chart->set_title(title_); chart->set_id(id_); + + for (const auto& kv : yaxis_tick_labels_) { + webrtc::analytics::TickLabel* tick = chart->add_yaxis_tick_labels(); + tick->set_value(kv.first); + tick->set_label(kv.second); + } } ProtobufPlotCollection::ProtobufPlotCollection() {} diff --git a/rtc_tools/event_log_visualizer/plot_python.cc b/rtc_tools/event_log_visualizer/plot_python.cc index b29c09212f..917ea11725 100644 --- a/rtc_tools/event_log_visualizer/plot_python.cc +++ b/rtc_tools/event_log_visualizer/plot_python.cc @@ -150,6 +150,17 @@ void PythonPlot::Draw() { printf("plt.xlabel(\'%s\')\n", xaxis_label_.c_str()); printf("plt.ylabel(\'%s\')\n", yaxis_label_.c_str()); printf("plt.title(\'%s\')\n", title_.c_str()); + printf("fig = plt.gcf()\n"); + printf("fig.canvas.set_window_title(\'%s\')\n", id_.c_str()); + if (!yaxis_tick_labels_.empty()) { + printf("yaxis_tick_labels = ["); + for (const auto& kv : yaxis_tick_labels_) { + printf("(%f,\"%s\"),", kv.first, kv.second.c_str()); + } + printf("]\n"); + printf("yaxis_tick_labels = list(zip(*yaxis_tick_labels))\n"); + printf("plt.yticks(*yaxis_tick_labels)\n"); + } if (!series_list_.empty() || !interval_list_.empty()) { printf("handles, labels = plt.gca().get_legend_handles_labels()\n"); printf("for lp in legend_patches:\n"); diff --git a/rtc_tools/event_log_visualizer/proto/chart.proto b/rtc_tools/event_log_visualizer/proto/chart.proto index aa518a767d..e5960b2677 100644 --- a/rtc_tools/event_log_visualizer/proto/chart.proto +++ b/rtc_tools/event_log_visualizer/proto/chart.proto @@ -13,6 +13,11 @@ message DataSet { bool highlight_points = 5; } +message TickLabel { + float value = 1; + string label = 2; +} + message Chart { repeated DataSet data_sets = 1; float xaxis_min = 2; @@ -23,6 +28,7 @@ message Chart { string yaxis_label = 7; string title = 8; string id = 9; + repeated TickLabel yaxis_tick_labels = 10; } message ChartCollection {