使用ggplot库将图形保存到jpg文件中

时间:2016-02-10 06:46:30

标签: python pandas python-ggplot

GGplot文档似乎表明你可以使用设备参数将数字保存为jpg,但是当我尝试使用它时,我得到错误:异常,`

  

未知格式jpg。

def chart(dataframe, stock_name, title):
    title = str(title)
    name = str(stock_name)
    graph_title = "TYD Chart for " + title
    df = dataframe.set_index('date')
    df = df[(df["stock_name"]==name)].ix['2016/01/01':'2016/02/09']
    ggplot_obj = ggplot(df.reset_index(), aes('date','close')) + geom_line() + ggtitle(graph_title)
    ggsave(filename="/Users/Joshua/Documents/stocks/" + title, device="jpg",plot = ggplot_obj, width = 10, height = 6)
    print ("Saved File for " + str(title))

使用the tutorial here on GGSAVE

将文件保存到png

1 个答案:

答案 0 :(得分:-2)

使用此处的教程GGSAVE tutorial,将文件保存为png而不是JPG。

相关问题