Add y-axis tick labels.

This is intended to by used for visualizing catagorical data, i.e. mapping
numerical enum values to string labels.

Bug: webrtc:10623
Change-Id: Ic9c3da9a3874f479c07412f394a774ae90fd3d7e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/145408
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Commit-Queue: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28656}
This commit is contained in:
Bjorn Terelius
2019-07-24 11:42:53 +02:00
committed by Commit Bot
parent 46bbdec1ab
commit 54d9602fe1
5 changed files with 32 additions and 0 deletions

View File

@ -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<std::pair<float, std::string>>& labels) {
yaxis_tick_labels_ = labels;
}
void Plot::SetTitle(const std::string& title) {
title_ = title;
}

View File

@ -137,6 +137,9 @@ class Plot {
float bottom_margin = 0,
float top_margin = 0);
void SetYAxisTickLabels(
const std::vector<std::pair<float, std::string>>& 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<std::pair<float, std::string>> yaxis_tick_labels_;
std::string title_;
std::string id_;
std::vector<TimeSeries> series_list_;

View File

@ -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() {}

View File

@ -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");

View File

@ -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 {