From: Vladimír Vondruš Date: Tue, 9 Jun 2020 16:25:06 +0000 (+0200) Subject: m.plots: allow to specify plot width also. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~cjwatson/git?a=commitdiff_plain;h=a66a05e988611cbeb7163dabe68f3ea1e4c8b237;p=blog.git m.plots: allow to specify plot width also. --- diff --git a/doc/plugins/plots-and-graphs.rst b/doc/plugins/plots-and-graphs.rst index 9d8a97a6..a334cf13 100644 --- a/doc/plugins/plots-and-graphs.rst +++ b/doc/plugins/plots-and-graphs.rst @@ -126,7 +126,9 @@ 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. 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`. +the bar height using :rst:`:bar-height:`. Default value is :py:`0.4`. Similarly +it's possible to specify graph width using :rst:`:plot-width:`, the default +:py:`8` is tuned for a page-wide plot. 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 diff --git a/plugins/m/plots.py b/plugins/m/plots.py index c3072a1f..83429905 100644 --- a/plugins/m/plots.py +++ b/plugins/m/plots.py @@ -142,6 +142,7 @@ class Plot(rst.Directive): 'values': directives.unchanged_required, 'errors': directives.unchanged, 'colors': directives.unchanged, + 'plot-width': directives.unchanged, 'bar-height': directives.unchanged, # Legacy options with ugly underscores instead of dashes 'labels_extra': directives.unchanged, @@ -214,7 +215,7 @@ class Plot(rst.Directive): # Setup the graph fig, ax = plt.subplots() # TODO: let matplotlib calculate the height somehow - fig.set_size_inches(8, 0.78 + len(labels)*bar_height) + fig.set_size_inches(float(self.options.get('plot-width', 8)), 0.78 + len(labels)*bar_height) yticks = np.arange(len(labels)) left = np.array([0.0]*len(labels)) for i in range(len(value_sets)): diff --git a/plugins/m/test/plots/page-py35.html b/plugins/m/test/plots/page-py35.html index 3e538545..3fa7caf9 100644 --- a/plugins/m/test/plots/page-py35.html +++ b/plugins/m/test/plots/page-py35.html @@ -160,8 +160,10 @@ div.m-plot svg { font-family: DejaVu Sans; } +
+

A plot with separate colors, extra labels, error bars and custom width + height

- +
+
diff --git a/plugins/m/test/plots/page.html b/plugins/m/test/plots/page.html index f8ab90ad..4ece1575 100644 --- a/plugins/m/test/plots/page.html +++ b/plugins/m/test/plots/page.html @@ -160,8 +160,10 @@ div.m-plot svg { font-family: DejaVu Sans; }
+
+

A plot with separate colors, extra labels, error bars and custom width + height

- +
+
diff --git a/plugins/m/test/plots/page.rst b/plugins/m/test/plots/page.rst index 480d070e..fcf81193 100644 --- a/plugins/m/test/plots/page.rst +++ b/plugins/m/test/plots/page.rst @@ -19,21 +19,29 @@ predictable rendering on the CIs. :values: 15 30 :colors: success -.. plot:: A plot with separate colors, extra labels, error bars and custom height - :type: barh - :labels: - January - February - March - :labels_extra: - a paradise - .. - hell! - :units: Mondays - :values: 3 4 5 - :errors: 0.1 2.1 1.0 - :colors: success info danger - :bar_height: 0.75 +.. using legacy underscored options below to test the compatibility (the dashed + options are used on the site, which should be enough to verify those work) + +.. container:: m-col-m-6 m-center-m + + A plot with separate colors, extra labels, error bars and custom width + height + + .. plot:: Yes. + :type: barh + :labels: + January + February + March + :labels_extra: + a paradise + .. + hell! + :units: Mondays + :values: 3 4 5 + :errors: 0.1 2.1 1.0 + :colors: success info danger + :plot-width: 4.5 + :bar_height: 0.75 .. plot:: Stacked plot :type: barh