Search code examples
pythonpython-2.7matplotlibggplot2python-ggplot

Python ggplot format axis number as percent not functioning


Been loving the new ggplot module in Python but I haven't been able to format my y labels as percent instead of decimals. The below code produces the following image. Note that the labels = 'percent' code does not produce the intended format.

plot = ggplot(aes(x='Date', y='return', color='Stocks'),data=rx) +\
geom_line() +\
scale_x_date(breaks=date_breaks('1 day'), labels='%b %d %Y') +\
scale_y_continuous(labels= 'percent') +\
ylab('Cumulative Return') + ggtitle('S&P Sector Performance') 

enter image description here


Solution

  • This is now available in version 0.5.3 (I just pushed this).

    >>> from ggplot import *
    >>> import numpy as np
    >>> import pandas as pd
    >>> df = pd.DataFrame({ "x": np.arange(0, 10), "y": np.arange(0, 1, 0.1) })
    >>> ggplot(df, aes(x='x', y='y')) +\
    ... geom_point() +\
    ... scale_y_continuous(labels='percent')
    

    ggplot scale_x_continuous percent