From: Vladimír Vondruš Date: Wed, 12 Sep 2018 10:39:42 +0000 (+0200) Subject: m.plots: make it possible to hide particular extra labels. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=ae2ce8ccc2d2afaff81476b1fc590d95878cb25a;p=blog.git m.plots: make it possible to hide particular extra labels. --- diff --git a/doc/plugins/plots-and-graphs.rst b/doc/plugins/plots-and-graphs.rst index ce4816bd..b2ac3394 100644 --- a/doc/plugins/plots-and-graphs.rst +++ b/doc/plugins/plots-and-graphs.rst @@ -113,11 +113,14 @@ labels. Hovering over the bars will show the concrete value in a title. It's also optionally possible to add error bars using :rst:`:error:` and configure bar colors using :rst:`:colors:`. The colors correspond to m.css `color classes <{filename}/css/components.rst#colors>`_ and you can either -use one color for all or one for each value, separated by whitespace. It's -possible to add an extra line of labels using :rst:`:labels_extra:`. Bar chart +use one color for all or one for each value, separated by whitespace. Bar chart height is calculated automatically based on amount of values, you can adjust the bar height using :rst:`:bar_height:`. Default value is :py:`0.4`. +It's possible to add an extra line of labels using :rst:`:labels_extra:`. +Again, there should be as many entries as primary labels and values. To omit an extra label for a value, specify it as the :abbr:`reST ` +comment :rst:`..`. + .. code-figure:: .. code:: rst @@ -133,7 +136,7 @@ the bar height using :rst:`:bar_height:`. Default value is :py:`0.4`. 15 modules 60 modules 200 modules - for comparison + .. :units: µs :values: 15.09 84.98 197.13 934.27 :errors: 0.74 3.65 9.45 25.66 @@ -151,7 +154,7 @@ the bar height using :rst:`:bar_height:`. Default value is :py:`0.4`. 15 modules 60 modules 200 modules - for comparison + .. :units: µs :values: 15.09 84.98 197.13 934.27 :errors: 0.74 3.65 9.45 25.66 diff --git a/pelican-plugins/m/plots.py b/pelican-plugins/m/plots.py index 42f95dc0..1469ca78 100644 --- a/pelican-plugins/m/plots.py +++ b/pelican-plugins/m/plots.py @@ -203,8 +203,9 @@ class Plot(rst.Directive): # with first having the second line empty and second having the first # line empty. if labels_extra: - ax.set_yticklabels([y + '\n' for y in labels]) + ax.set_yticklabels([y + ('' if labels_extra[i] == '..' else '\n') for i, y in enumerate(labels)]) for i, label in enumerate(ax.get_yticklabels()): + if labels_extra[i] == '..': continue ax.text(0, i + 0.05, '\n' + labels_extra[i], va='center', ha='right', transform=label.get_transform(), color='#cafe0b') diff --git a/pelican-plugins/m/test/plots/page-travis-broken-matplotlib-seed.html b/pelican-plugins/m/test/plots/page-travis-broken-matplotlib-seed.html index c676996e..62592f13 100644 --- a/pelican-plugins/m/test/plots/page-travis-broken-matplotlib-seed.html +++ b/pelican-plugins/m/test/plots/page-travis-broken-matplotlib-seed.html @@ -281,8 +281,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - February - + February @@ -324,14 +323,10 @@ div.m-plot svg { font-family: DejaVu Sans; } a paradise - - okay - - hell! - + A plot with separate colors, extra labels, error bars and custom height diff --git a/pelican-plugins/m/test/plots/page.html b/pelican-plugins/m/test/plots/page.html index 5bf4c214..896edd1f 100644 --- a/pelican-plugins/m/test/plots/page.html +++ b/pelican-plugins/m/test/plots/page.html @@ -281,8 +281,7 @@ div.m-plot svg { font-family: DejaVu Sans; } - February - + February @@ -324,14 +323,10 @@ div.m-plot svg { font-family: DejaVu Sans; } a paradise - - okay - - hell! - + A plot with separate colors, extra labels, error bars and custom height diff --git a/pelican-plugins/m/test/plots/page.rst b/pelican-plugins/m/test/plots/page.rst index d0925f3c..295429a5 100644 --- a/pelican-plugins/m/test/plots/page.rst +++ b/pelican-plugins/m/test/plots/page.rst @@ -27,7 +27,7 @@ predictable rendering on the CIs. March :labels_extra: a paradise - okay + .. hell! :units: Mondays :values: 3 4 5