Seaborn / Matplotlib图未轴未显示正确值

时间:2018-11-28 23:18:13

标签: python matplotlib anaconda jupyter-notebook seaborn

我正在为一个班级进行数据分析项目,并且遇到了我无法真正解决的问题。当我对数据集运行代码并使用Seaborn / Matplotlib在Jupyter Notebook中打印图形时,X,Y轴显示的值不正确。 X轴应该是电影预算的范围,但是以25个数字为增量进行计数,Y轴应该是从1960年到2015年的几年范围,但是该轴只是标记为1到5。我要缺少什么,以便该图添加我需要的预算和年份范围。

下面是我打印图形之前的代码。导致这种情况的代码是清理和组织数据的代码。

Screenshot from Jupyter Notebook of Seaborn code and graph with the issue Code and graph teaching how to use Seaborn and matplotlib

GitHub repository with Jupyter Notebook: Investigate a Dataset

# Compute the Mean for budget vs. runtime
p_mean = df.groupby('budget').mean()['runtime']
p_mean.tail()

budget
260000000.0    116.
280000000.0    141.0
300000000.0    169.0
380000000.0    136.0
425000000.0    100.0
Name: runtime, dtype: float64

# build the index location for x-axis
index_mean = p_mean.index

#set style
sns.set_style('whitegrid')
#set x, y axis data
#x1, y1 for mean data; x2, y2 for median data
x1, y1 = index_mean, p_mean
#set size
plt.figure(figsize=(15, 8))
#plot line chart for mean and median
plt.plot(x1, y1, color = 'r', label = 'mean')
#set title and labels
plt.title('Budget vs. Movie Runtime')
plt.xlabel('Budget')
plt.ylabel('Runtime');
#set legend
plt.legend(loc='upper left')
plt.show()

0 个答案:

没有答案