如何使用Python在Seaborn中保存地块 [英] How to save a plot in Seaborn with Python

查看:95
本文介绍了如何使用Python在Seaborn中保存地块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Pandas数据框,并尝试将绘图保存为png文件.但是,似乎有些事情没有按预期进行.这是我的代码:

I have a Pandas dataframe and try to save a plot in a png file. However, it seems that something doesn't work as it should. This is my code:

import pandas
import matplotlib.pyplot as plt
import seaborn as sns

sns.set(style='ticks')

df = pandas.read_csv("this_is_my_csv_file.csv")
plot = sns.distplot(df[['my_column_to_plot']])
plot.savefig("myfig.png")

我有这个错误:

AttributeError: 'AxesSubplot' object has no attribute 'savefig'

推荐答案

您可以使用plt.savefig,因为当您致电plt.show()

You could use plt.savefig because your picture will come up when you'll call plt.show()

这篇关于如何使用Python在Seaborn中保存地块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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