Skip to content
Snippets Groups Projects
Unverified Commit ad9d8946 authored by Nick Draper's avatar Nick Draper Committed by GitHub
Browse files

Merge pull request #28175 from mantidproject/Remove_None_entry_from_legend_title

Remove 'None' title in the legend of 1D plots
parents b2e5c4aa bf5c173c
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,11 @@ class LegendProperties(dict):
else:
props['title'] = None
# For Matplotlib <3.2 we have to remove the 'None' string from the title
# which is generated by set_text() in text.py
if props['title'] == 'None':
props['title'] = ''
props['title_font'] = title.get_fontname()
props['title_size'] = title.get_fontsize()
props['title_color'] = convert_color_to_hex(title.get_color())
......@@ -127,10 +132,6 @@ class LegendProperties(dict):
@classmethod
def create_legend(cls, props, ax):
# For Matplotlib <3.2 we have to remove the 'None' string from the title
# which is generated by set_text() in text.py
if props['title'] == 'None':
props['title'] = ''
if int(matplotlib.__version__[0]) >= 2:
legend = ax.legend(ncol=props['columns'],
prop={'size': props['entries_size']},
......
......@@ -10,6 +10,7 @@ from __future__ import absolute_import
import unittest
import matplotlib.pyplot as plt
from mantid.plots.legend import LegendProperties
from numpy import testing as np_testing
from mantid.plots.utility import zoom, zoom_axis
......@@ -25,12 +26,21 @@ class TestUtility(unittest.TestCase):
ax.plot([0, 1, 2], [6, 4, 6])
zoom_point = [2, 6]
factor = 1/1.1 # = 0.909090...
factor = 1 / 1.1 # = 0.909090...
xlims, ylims = zoom(ax, *zoom_point, factor=factor)
np_testing.assert_almost_equal([-0.31, 2.11], xlims)
np_testing.assert_almost_equal([3.69, 6.11], ylims)
def test_from_legend_correctly_returns_properties_if_title_is_none(self):
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [6, 4, 6])
ax.legend(labels='A', title=None)
legend_props = LegendProperties.from_legend(ax.legend_)
self.assertEqual(legend_props['title'], '')
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment