Python ggplot格式轴数百分比不起作用 [英] Python ggplot format axis number as percent not functioning

查看:121
本文介绍了Python ggplot格式轴数百分比不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于喜欢用Python中的新ggplot模块,但是我无法将y标签的格式设置为百分比而不是小数.下面的代码产生以下图像.请注意,labels ='percent'代码不会产生预期的格式.

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

推荐答案

现在可以在版本0.5.3中使用(我刚刚推送了此版本).

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

这篇关于Python ggplot格式轴数百分比不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆