Skip to content

Commit 1407a9f

Browse files
committed
geom_linerange: Support for categorical x
Signed-off-by: Matthias Kümmerer <matthias@matthias-k.org>
1 parent 884d6cc commit 1407a9f

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

ggplot/geoms/geom_linerange.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
unicode_literals)
33
import matplotlib as mpl
44
from .geom import geom
5+
from ggplot.utils import is_string
6+
from ggplot.utils import is_categorical
57
import numpy as np
68

79
class geom_linerange(geom):
@@ -16,6 +18,14 @@ class geom_linerange(geom):
1618
_units = {'alpha', 'color', 'linestyle'}# 'marker'}
1719

1820
def _plot_unit(self, pinfo, ax):
21+
# If x is categorical, calculate positions to plot
22+
categorical = is_categorical(pinfo['x'])
23+
if categorical:
24+
x = pinfo.pop('x')
25+
new_x = np.arange(len(x))
26+
ax.set_xticks(new_x)
27+
ax.set_xticklabels(x)
28+
pinfo['x'] = new_x
1929

2030
if 'linewidth' in pinfo and isinstance(pinfo['linewidth'], list):
2131
# ggplot also supports aes(size=...) but the current mathplotlib
@@ -28,22 +38,6 @@ def _plot_unit(self, pinfo, ax):
2838
sys.stderr.write(msg)
2939
self._warning_printed = True
3040

31-
#_abscent = {None: pinfo['color'], False: ''}
32-
#try:
33-
# if pinfo['facecolor'] in _abscent:
34-
# pinfo['facecolor'] = _abscent[pinfo['facecolor']]
35-
#except TypeError:
36-
# pass
37-
38-
# for some reason, scatter doesn't default to the same color styles
39-
# as the axes.color_cycle
40-
#f "color" not in pinfo and self.params['cmap'] is None:
41-
# pinfo["color"] = mpl.rcParams.get("axes.color_cycle", ["#333333"])[0]
42-
43-
#if self.params['position'] == 'jitter':
44-
# pinfo['x'] *= np.random.uniform(.9, 1.1, len(pinfo['x']))
45-
# pinfo['y'] *= np.random.uniform(.9, 1.1, len(pinfo['y']))
46-
4741
x = pinfo.pop('x')
4842
x = np.vstack([x, x])
4943

0 commit comments

Comments
 (0)