Data Science Machine Learning Data Analysis
37.9K subscribers
2.79K photos
30 videos
39 files
1.26K links
This channel is for Programmers, Coders, Software Engineers.

1- Data Science
2- Machine Learning
3- Data Visualization
4- Artificial Intelligence
5- Data Analysis
6- Statistics
7- Deep Learning

Cross promotion and ads: @hussein_sheikho
Download Telegram
Topic: Python Matplotlib – Important 20 Interview Questions with Answers

---

### 1. What is Matplotlib in Python?

Answer:
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It is highly customizable and works well with NumPy and pandas.

---

### 2. What is the difference between `plt.plot()` and `plt.scatter()`?

Answer:
plt.plot() is used for line plots.
plt.scatter() is used for creating scatter (dot) plots.

---

### 3. How do you add a title and axis labels to a plot?

Answer:

plt.title("My Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")


---

### 4. How can you create multiple subplots in one figure?

Answer:
Use plt.subplots() to create a grid layout of subplots.

fig, axs = plt.subplots(2, 2)


---

### 5. How do you save a plot to a file?

Answer:

plt.savefig("myplot.png", dpi=300)


---

### 6. What is the role of `plt.show()`?

Answer:
It displays the figure window containing the plot. Required for interactive sessions or scripts.

---

### 7. What is a histogram in Matplotlib?

Answer:
A histogram is used to visualize the frequency distribution of numeric data using plt.hist().

---

### 8. What does `plt.figure(figsize=(8,6))` do?

Answer:
It creates a new figure with a specified width and height (in inches).

---

### 9. How do you add a legend to your plot?

Answer:

plt.legend()


You must specify label='something' in your plot function.

---

### 10. What are some common `cmap` (color map) options?

Answer:
'viridis', 'plasma', 'hot', 'coolwarm', 'gray', 'jet', etc.

---

### 11. How do you create a bar chart?

Answer:

plt.bar(categories, values)


---

### 12. How can you rotate x-axis tick labels?

Answer:

plt.xticks(rotation=45)


---

### 13. How do you add a grid to the plot?

Answer:

plt.grid(True)


---

### 14. What is the difference between `imshow()` and `matshow()`?

Answer:
imshow() is general-purpose for image data.
matshow() is optimized for 2D matrices and auto-configures the axes.

---

### 15. How do you change the style of a plot globally?

Answer:

plt.style.use('ggplot')


---

### 16. How can you add annotations to specific data points?

Answer:

plt.annotate('label', xy=(x, y), xytext=(x+1, y+1), arrowprops=dict(arrowstyle='->'))


---

### 17. How do you create a pie chart in Matplotlib?

Answer:

plt.pie(data, labels=labels, autopct='%1.1f%%')


---

### 18. How do you plot a heatmap in Matplotlib?

Answer:

plt.imshow(matrix, cmap='hot')
plt.colorbar()


---

### 19. Can Matplotlib create 3D plots?

Answer:
Yes. Use:

from mpl_toolkits.mplot3d import Axes3D


Then:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')


---

### 20. How do you add error bars to your data?

Answer:

plt.errorbar(x, y, yerr=errors, fmt='o')


---

### Exercise

Choose 5 of the above functions and implement a mini-dashboard with line, bar, and pie plots in one figure layout.

---

#Python #Matplotlib #InterviewQuestions #DataVisualization #TechInterview

https://t.iss.one/DataScienceM
4👍1