2

一直喜欢 Python 中的新 ggplot 模块,但我无法将我的 y 标签格式化为百分比而不是小数。以下代码生成以下图像。请注意,labels = 'percent' 代码不会产生预期的格式。

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') 

在此处输入图像描述

4

1 回答 1

3

这现在在 0.5.3 版本中可用(我刚刚推送了这个)。

>>> 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 百分比

于 2014-04-24T15:12:04.117 回答