# I keep having errors while making graphs in python

**URL:** <https://discuss.python.org/t/i-keep-having-errors-while-making-graphs-in-python/36147>\
**Category:** Python Help\
**Tags:** help\
**Created:** [October 14, 2023, 2:08am UTC](https://discuss.python.org/t/i-keep-having-errors-while-making-graphs-in-python/36147 "2023-10-14T02:08:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMin](https://avatars.discourse-cdn.com/v4/letter/a/8e7dd6/32.png) [@AMin](https://discuss.python.org/u/AMin)\
**Post date:** [October 14, 2023, 2:08am UTC](https://discuss.python.org/t/i-keep-having-errors-while-making-graphs-in-python/36147/1 "2023-10-14T02:08:21Z")

</div>

# 5

Use [plt.subplot] to create a figure with four subplots (2 rows and 2 columns) as shown below. Specify the figure size to be 8 by 6. Develop all charts using matplotlib (not seaborn). For each chart, include the title, x & y labels as needed.

Chart information:

- Top left: Bar chart showing the counts of No MBA and MBA Employees
- Top right: Scatter plot showing the relationship between Age and Salary
- Bottom left: Histogram showing the salary distribution for Non-MBA Employees
- Bottom right: Histogram showing the salary distribution for MBA Employees

# Task 0: Import libaries and load data frame

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

# Set the plot style

plt.style.use(“ggplot”)

# Load the CSV data file

df = pd.read\_csv(r"[https://raw.githubusercontent.com/babdelfa/class/main/EmployeeSalaries.csv](https://raw.githubusercontent.com/babdelfa/class/main/EmployeeSalaries.csv)")

# Display a sample of the dataframe

print(df.head())

# Bottom left: Histogram for non-MBA employees’ salaries

df[df[“MBA”] == False][“Salaries”].plot(kind=“hist”, ax=ax[1, 0])  
ax[1, 0].set\_title(“Salary Distribution for Non-MBA Employees”)  
ax[1, 0].set\_xlabel(“Salary”)  
ax[1, 0].set\_ylabel(“Frequency”)

# Bottom right: Histogram for MBA employees’ salaries

df[df[“MBA”] == True][“Salaries”].plot(kind=“hist”, ax=ax[1, 1])  
ax[1, 1].set\_title(“Salary Distribution for MBA Employees”)  
ax[1, 1].set\_xlabel(“Salary”)  
ax[1, 1].set\_ylabel(“Frequency”)

# Adjust layout

plt.tight\_layout()  
plt.show()

 ![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/2X/7/7378c6181a809a501f43fb39da7101bc25c90de7.png)

The above is the codes I wrote  
and I keep having errors.  
Please tell me how I can solve them please

---

<div class="post-metadata">

**Author:** ![MRAB](https://avatars.discourse-cdn.com/v4/letter/m/e9c0ed/32.png) [@MRAB](https://discuss.python.org/u/MRAB)\
**Post date:** [October 14, 2023, 3:04am UTC](https://discuss.python.org/t/i-keep-having-errors-while-making-graphs-in-python/36147/2 "2023-10-14T03:04:00Z")

</div>

“I keep having errors”?

You need to say what errors you’re having.

If it’s printing a traceback, then post that, select it, and click `</>` to preserve its formatting. (Also do that when posting code to preserve its formatting.)
