Skip to content

Commit b737828

Browse files
committed
Use scale.name parameter for the axis-title
This is inline with the documentation, it was simply ignored for the position scales. Other scales were not affected. fixes #105
1 parent 4a8f7f1 commit b737828

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

doc/changelog.rst

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Bug Fixes
4444
:class:`~plotnine.stats.stat_bin_2d` to properly handle the
4545
``breaks`` parameter when used with a transforming scale.
4646

47+
- Fixed issue with x and y scales where the ``name`` of the scale was
48+
ignored when determining the axis titles. Now, the ``name`` parameter
49+
is specified, it is used as the title. (:issue:`105`)
50+
4751
v0.3.0
4852
------
4953
*(2017-11-08)*

plotnine/facets/layout.py

+34
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,37 @@ def check_layout(self):
202202
raise PlotnineError(
203203
"Facet layout has bad format. It must contain "
204204
"the columns '{}'".format(required))
205+
206+
def xlabel(self, labels):
207+
"""
208+
Determine x-axis label
209+
210+
Parameters
211+
----------
212+
labels : dict
213+
Labels as specified by the user through the ``labs`` or
214+
``xlab`` calls.
215+
216+
Returns
217+
-------
218+
out : str
219+
x-axis label
220+
"""
221+
return self.panel_scales_x[0].name or labels.get('x', '')
222+
223+
def ylabel(self, labels):
224+
"""
225+
Determine x-axis label
226+
227+
Parameters
228+
----------
229+
labels : dict
230+
Labels as specified by the user through the ``labs`` or
231+
``ylab`` calls.
232+
233+
Returns
234+
-------
235+
out : str
236+
y-axis label
237+
"""
238+
return self.panel_scales_y[0].name or labels.get('y', '')

plotnine/ggplot.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,10 @@ def _draw_labels(self):
498498

499499
# Get the axis labels (default or specified by user)
500500
# and let the coordinate modify them e.g. flip
501-
labels = self.coordinates.labels(
502-
{'x': self.labels.get('x', ''),
503-
'y': self.labels.get('y', '')})
501+
labels = self.coordinates.labels({
502+
'x': self.layout.xlabel(self.labels),
503+
'y': self.layout.ylabel(self.labels)
504+
})
504505

505506
# The first axes object is on left, and the last axes object
506507
# is at the bottom. We change the transform so that the relevant

0 commit comments

Comments
 (0)