问题
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')
![](https://www.eimg.top/images/2020/03/25/e3c9370d6e743957ae2535a569936405.png)
回答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://www.eimg.top/images/2020/03/25/6043c9a43cd8ec03981b22dc72c45b2a.png)
来源:https://stackoverflow.com/questions/23226818/python-ggplot-format-axis-number-as-percent-not-functioning