matplotlib - In ggplot for Python, using discrete X scale with geom_point()? -


the following example returns error. appears using discrete (not continuous) scale x-axis in ggplot in python not supported?

import pandas pd import ggplot  df = pd.dataframe.from_dict({'a':['a','b','c'],                    'percentage':[.1,.2,.3]})  p = ggplot.ggplot(data=df,                   aesthetics=ggplot.aes(x='a',                                         y='percentage'))\     + ggplot.geom_point()  print(p) 

as mentioned, returns:

traceback (most recent call last):   file "/users/me/library/preferences/pycharm2016.1/scratches/scratch_1.py", line 30, in <module>     print(p)   file "/users/me/lib/python3.5/site-packages/ggplot/ggplot.py", line 116, in __repr__     self.make()   file "/users/me/lib/python3.5/site-packages/ggplot/ggplot.py", line 627, in make     layer.plot(ax, facetgroup, self._aes, **kwargs)   file "/users/me/lib/python3.5/site-packages/ggplot/geoms/geom_point.py", line 60, in plot     ax.scatter(x, y, **params)   file "/users/me/lib/python3.5/site-packages/matplotlib/__init__.py", line 1819, in inner     return func(ax, *args, **kwargs)   file "/users/me/lib/python3.5/site-packages/matplotlib/axes/_axes.py", line 3838, in scatter     x, y, s, c = cbook.delete_masked_points(x, y, s, c)   file "/users/me/lib/python3.5/site-packages/matplotlib/cbook.py", line 1848, in delete_masked_points     raise valueerror("first argument must sequence") valueerror: first argument must sequence 

any workarounds using ggplot scatters on discrete scale?

one option generate continuous series, , use original variable labels. seems painful workaround.

df = pd.dataframe.from_dict( {'a':[0,1,2],                    'a_name':['a','b','c'],                    'percentage':[.1,.2,.3]})  p = ggplot.ggplot(data=df,                   aesthetics=ggplot.aes(x='a',                                         y='percentage'))\     + ggplot.geom_point()\     + ggplot.scale_x_continuous(breaks=list(df['a']),                               labels=list(df['a_name'])) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -