Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent handing of axis label and tick fontsize #1162

Merged
merged 3 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions holoviews/plotting/bokeh/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,11 @@ def _title_properties(self, key, plot, element):
title_font = self._fontsize('title', 'title_text_font_size')
return dict(title=title, title_text_color='black', **title_font)
else:
title_font = self._fontsize('title', 'text_font_size')
title_font['text_font_size'] = value(title_font['text_font_size'])
return dict(text=title, text_color='black', **title_font)

opts = dict(text=title, text_color='black')
title_font = self._fontsize('title').get('fontsize')
if title_font:
opts['text_font_size'] = value(title_font)
return opts

def _init_axes(self, plot):
if self.xaxis is None:
Expand Down Expand Up @@ -420,6 +421,12 @@ def _axis_properties(self, axis, key, plot, dimension=None,
axis_props['major_tick_line_color'] = None
axis_props['minor_tick_line_color'] = None
else:
labelsize = self._fontsize('%slabel' % axis).get('fontsize')
if labelsize:
axis_props['axis_label_text_font_size'] = labelsize
ticksize = self._fontsize('%sticks' % axis, common=False).get('fontsize')
if ticksize:
axis_props['major_label_text_font_size'] = value(ticksize)
rotation = self.xrotation if axis == 'x' else self.yrotation
if rotation:
axis_props['major_label_orientation'] = np.radians(rotation)
Expand Down
5 changes: 3 additions & 2 deletions holoviews/plotting/mpl/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ def _finalize_ticks(self, axis, dimensions, xticks, yticks, zticks):
self._set_axis_ticks(axis.zaxis, zticks, log=self.logz,
rotation=self.zrotation)

tick_fontsize = self._fontsize('ticks','labelsize',common=False)
if tick_fontsize: axis.tick_params(**tick_fontsize)
for ax, ax_obj in zip('xy', [axis.xaxis, axis.yaxis]):
tick_fontsize = self._fontsize('%sticks' % ax,'labelsize',common=False)
if tick_fontsize: ax_obj.set_tick_params(**tick_fontsize)


def _finalize_artist(self, element):
Expand Down
5 changes: 3 additions & 2 deletions holoviews/plotting/mpl/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ def _layout_axis(self, layout, axis):
layout_axis.set_position(self.position)
layout_axis.patch.set_visible(False)

tick_fontsize = self._fontsize('ticks','labelsize',common=False)
if tick_fontsize: layout_axis.tick_params(**tick_fontsize)
for ax, ax_obj in zip(['x', 'y'], [layout_axis.xaxis, layout_axis.yaxis]):
tick_fontsize = self._fontsize('%sticks' % ax,'labelsize', common=False)
if tick_fontsize: ax_obj.set_tick_params(**tick_fontsize)

# Set labels
layout_axis.set_xlabel(str(layout.kdims[0]),
Expand Down
5 changes: 4 additions & 1 deletion holoviews/plotting/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ class DimensionedPlot(Plot):

#Allowed fontsize keys
_fontsize_keys = ['xlabel','ylabel', 'labels', 'ticks',
'title', 'legend', 'legend_title']
'title', 'legend', 'legend_title', 'xticks',
'yticks']

show_title = param.Boolean(default=True, doc="""
Whether to display the plot title.""")
Expand Down Expand Up @@ -298,6 +299,8 @@ def _fontsize(self, key, label='fontsize', common=True):
return {label:self.fontsize[key]}
elif key in ['ylabel', 'xlabel'] and 'labels' in self.fontsize:
return {label:self.fontsize['labels']}
elif key in ['xticks', 'yticks'] and 'ticks' in self.fontsize:
return {label:self.fontsize['ticks']}
else:
return {}

Expand Down
48 changes: 48 additions & 0 deletions tests/testplotinstantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,54 @@ def test_curve_heterogeneous_datetime_types_with_pd_overlay(self):
self.assertEqual(plot.handles['x_range'].start, np.datetime64(dt.datetime(2016, 1, 1)))
self.assertEqual(plot.handles['x_range'].end, np.datetime64(dt.datetime(2016, 1, 13)))

def test_curve_fontsize_xlabel(self):
curve = Curve(range(10))(plot=dict(fontsize={'xlabel': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['xaxis'].axis_label_text_font_size,
{'value': '14pt'})

def test_curve_fontsize_ylabel(self):
curve = Curve(range(10))(plot=dict(fontsize={'ylabel': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['yaxis'].axis_label_text_font_size,
{'value': '14pt'})

def test_curve_fontsize_both_labels(self):
curve = Curve(range(10))(plot=dict(fontsize={'labels': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['xaxis'].axis_label_text_font_size,
{'value': '14pt'})
self.assertEqual(plot.handles['yaxis'].axis_label_text_font_size,
{'value': '14pt'})

def test_curve_fontsize_xticks(self):
curve = Curve(range(10))(plot=dict(fontsize={'xticks': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['xaxis'].major_label_text_font_size,
{'value': '14pt'})

def test_curve_fontsize_yticks(self):
curve = Curve(range(10))(plot=dict(fontsize={'yticks': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['yaxis'].major_label_text_font_size,
{'value': '14pt'})

def test_curve_fontsize_both_ticks(self):
curve = Curve(range(10))(plot=dict(fontsize={'ticks': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['xaxis'].major_label_text_font_size,
{'value': '14pt'})
self.assertEqual(plot.handles['yaxis'].major_label_text_font_size,
{'value': '14pt'})

def test_curve_fontsize_xticks_and_both_ticks(self):
curve = Curve(range(10))(plot=dict(fontsize={'xticks': '18pt', 'ticks': '14pt'}))
plot = bokeh_renderer.get_plot(curve)
self.assertEqual(plot.handles['xaxis'].major_label_text_font_size,
{'value': '18pt'})
self.assertEqual(plot.handles['yaxis'].major_label_text_font_size,
{'value': '14pt'})

def test_layout_gridspaces(self):
layout = (GridSpace({(i, j): Curve(range(i+j)) for i in range(1, 3)
for j in range(2,4)}) +
Expand Down