0

I try to adjust the size of my figure. However, the moment I do that, by adding plt.figure(figsize=(10,5)) I don't see the dots anymore. The reason I want to change the size is mainly because of ylabel is not shown the way it is now. enter image description here enter image description here

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn import linear_model

# Check out the Data
df = pd.read_csv("https://s3.amazonaws.com/codecademy-content/programs/data-science-path/linear_regression/honeyproduction.csv")
# print(df.head())
# print(df.columns)

prod_per_year = df.groupby(['year']).totalprod.mean().reset_index()
# print(prod_per_year)

X = prod_per_year['year']
X = X.values.reshape(-1, 1)
y = prod_per_year['totalprod']

plt.scatter(X, y)
plt.xlabel('Year')
plt.ylabel('Total production')
plt.show()

# Create and Fit a Linear Regression Model
regr = linear_model.LinearRegression()
regr.fit(X, y)

# Print out the slope (regr.coef_) and the intercept (regr.intercept_)
print(regr.coef_)
print(regr.intercept_)

y_predict = regr.predict(X)
plt.figure(figsize=(10,5))
plt.plot(X, y_predict)
plt.show()
Georgy
  • 12,464
  • 7
  • 65
  • 73
Joey Coder
  • 3,199
  • 8
  • 28
  • 60
  • I think you are looking for the second answer in the duplicate target, as you are trying to change the size after the figure is already created. – Georgy Jun 15 '19 at 09:57
  • `plt.figure` needs to come before `plt.scatter`, else you will have one figure with a scatter and one figure which is 10 by 5 inches. – ImportanceOfBeingErnest Jun 15 '19 at 11:47
  • That answered my question, thank you. I didn't realize the order was wrong. Now it makes sense. – Joey Coder Jun 15 '19 at 12:32

0 Answers0