Python ggplot 格式轴编号作为百分比不起作用

标签 python python-2.7 matplotlib ggplot2 python-ggplot

一直喜欢 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') 

enter image description here

最佳答案

现在可以在 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 percent

关于Python ggplot 格式轴编号作为百分比不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23226818/

相关文章:

javascript - 在 Python 中从 WebSocket 读取(来自 Javascript WebSocket 的数据)

python - 使用 savefig() 从 matplotlib 导出时如何指定 .eps 的大小(尺寸)

Python:RoboBrowser 类型错误: 'NoneType'

python - django form.is_valid() 总是返回 false

python - 如何将 numpy 数组列表转换为单个 numpy 数组?

python-2.7 - 如何将 python Reportlab 表定位在位置 10,100 并使用 drawString

python - 有没有办法根据条件将 "fork"列表分成两部分

python - 使 python 循环更快

python - matplotlib 相当于 skimage.io.imread(fname, as_grey=True)?

python - 使用 matplotlib 进行实时绘图