情节摆脱空白

数据挖掘 可视化 绘图
2022-03-05 08:06:44

在此处输入图像描述

所以我正在用 Python 学习 Udemy 的数据科学课程,但情节发生了一些奇怪的事情。上图第一个是我的,第二个是导师。

如何摆脱侧面的空白,在 pandas 中使用绘图功能时,它们似乎是默认的。

编辑:这是所有的代码。一切基本上都是默认的,所以我猜 matplotlib 在新版本的包中更改了一些默认设置。df3 文件在这里https://github.com/sxsheng/Udemy

代码:

import pandas as pd

import matplotlib.pyplot as plt

df3 = pd.read_csv('df3')

%matplotlib inline (This line is to be used in jupyter notebooks to display plots)

df3['a'].plot.hist()
1个回答

欢迎来到本站!

您的想法是正确的,新版本的情节看起来有点不同,要获得与上面完全相同的情节,您可以使用以下代码:

import pandas as pd
import matplotlib.pyplot as plt    
df3 = pd.read_csv('df3')
#%matplotlib inline (This line is to be used in jupyter notebooks to display plots)

ax = plt.subplot(111)
ax.hist(df3['a'],ec='black')

#this is x axis limiter since your value ranges in between 0 to 1 I gave these values
plt.xlim([0,1])
plt.show()

结果:

结果

需要帮助请叫我。

如果这是您正在寻找的内容,那么您可以通过单击绿色对勾来接受答案。