Loading

Quipoin Menu

Learn • Practice • Grow

python / Matplotlib
interview

Q1. What is matplotlib used for?
matplotlib is a plotting library for creating static, animated, and interactive visualizations in Python. It provides a MATLAB-like interface for generating plots, histograms, bar charts, scatter plots, etc. It's widely used in data science for exploratory data analysis.

Q2. How do you create a simple line plot?
Use plt.plot() and plt.show(). Example:
import matplotlib.pyplot as plt x = [1,2,3,4] y = [10,20,25,30] plt.plot(x, y) plt.xlabel(''X'') plt.ylabel(''Y'') plt.title(''My Plot'') plt.show()

Q3. What is the difference between pyplot and pylab?
pyplot is a module within matplotlib that provides a MATLAB-like interface for plotting. pylab is a module that combines pyplot and numpy in a single namespace, but it's deprecated. The recommended approach is to import pyplot as plt.

Q4. How do you create subplots?
Use plt.subplots() or plt.subplot(). Example:
fig, axes = plt.subplots(2, 2) axes[0,0].plot(x, y) axes[0,1].scatter(x, y) plt.tight_layout()

Q5. How do you save a figure to a file?
Use plt.savefig(''filename.png'') before plt.show(). You can specify format (png, pdf, svg), DPI, etc. Example:
plt.plot(x, y) plt.savefig(''plot.png'', dpi=300)