Prepare Interview

Mock Exams

Make Homepage

The Best LIVE Mock Interview - You should go through before Interview

## Experienced / Expert level questions & answers

### Ques 1. How can you customize the color and style of a plot in Matplotlib?

You can use the `color` and `linestyle` parameters in the `plt.plot()` function to customize color and style.

Example:

`plt.plot([1, 2, 3, 4], [10, 20, 25, 30], color='green', linestyle='--')plt.show()`

### Ques 2. How can you create a 3D plot using Matplotlib?

Use the `mplot3d` toolkit in Matplotlib and functions like `ax.plot3D()` to create 3D plots.

Example:

`from mpl_toolkits import mplot3dfig = plt.figure()ax = fig.add_subplot(111, projection='3d')ax.plot3D([1, 2, 3, 4], [10, 20, 25, 30], [5, 10, 15, 20])plt.show()`

### Ques 3. What is the purpose of the `plt.fill_between()` function in Matplotlib?

`plt.fill_between()` is used to fill the area between two horizontal curves on the plot.

Example:

`x = [1, 2, 3, 4]y1 = [10, 20, 25, 30]y2 = [5, 15, 20, 25]plt.fill_between(x, y1, y2, color='gray', alpha=0.5)plt.show()`

### Ques 4. What is the purpose of the `plt.subplot2grid()` function in Matplotlib?

`plt.subplot2grid()` is used to create a subplot with a grid-like placement in the figure.

Example:

`plt.subplot2grid((2, 2), (0, 0))plt.plot([1, 2, 3, 4], [10, 20, 25, 30])plt.show()`

### Ques 5. What is the purpose of the `plt.subplot2grid()` function in Matplotlib?

`plt.subplot2grid()` is used to create a subplot with a grid-like placement in the figure.

Example:

`plt.subplot2grid((2, 2), (0, 0))plt.plot([1, 2, 3, 4], [10, 20, 25, 30])plt.show()`

### Ques 6. How can you create a streamplot in Matplotlib?

Use the `plt.streamplot()` function to create a streamplot, which visualizes a 2D vector field.

Example:

`import numpy as npx, y = np.meshgrid(np.linspace(-2, 2, 20), np.linspace(-2, 2, 20))u = np.cos(x)v = np.sin(y)plt.streamplot(x, y, u, v)plt.show()`

### Ques 7. What is the purpose of the `plt.subplot2grid()` function in Matplotlib?

`plt.subplot2grid()` is used to create a subplot with a grid-like placement in the figure.

Example:

`plt.subplot2grid((2, 2), (0, 0))plt.plot([1, 2, 3, 4], [10, 20, 25, 30])plt.show()`

### Ques 8. What is the purpose of the `plt.annotate()` function in Matplotlib?

`plt.annotate()` is used to add annotations with arrows to points on the plot.

Example:

`plt.plot([1, 2, 3, 4], [10, 20, 25, 30])plt.annotate('Max Value', xy=(3, 30), xytext=(2.5, 28), arrowprops=dict(facecolor='black', shrink=0.05))plt.show()`