12

当我尝试用 ggplot 绘制时间序列时,x 轴标签变得过于拥挤并相互重叠:

截图1

代码是:

plot = ggplot(df, aes(x=df.index, weight='COUNT')) + \
    geom_bar() + \
    xlab('Date') + \
    ylab('Incidents') 

我尝试添加以下行

+ theme(axis.text.x = element_text(angle = 90, hjust = 1))

到情节,但它不起作用。这个额外的行给了我错误:

SyntaxError: keyword can't be an expression
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr

知道这是怎么发生的,我应该如何解决?谢谢!!

4

1 回答 1

9

(老问题,如果将来有人遇到这个问题,请发布答案)

“axis.text.x”格式用于R。当使用ggplot for python时,将“axis.text.x”替换为“axis_text_x”

这对我有用:

theme(axis_text_x  = element_text(angle = 90, hjust = 1))

参考: https ://github.com/yhat/ggplot/blob/master/ggplot/themes/theme.py

于 2014-12-19T15:04:03.813 回答