问题
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')
回答1:
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')
来源:https://stackoverflow.com/questions/23226818/python-ggplot-format-axis-number-as-percent-not-functioning