Python Matplotlib perguntas e respostas de entrevista
Pergunta 11. How can you create a bar chart in Matplotlib?
Use the `plt.bar()` function to create a bar chart in Matplotlib.
Example:
plt.bar([1, 2, 3, 4], [10, 20, 25, 30])
plt.show()
Pergunta 12. Explain the purpose of the `plt.title()` function in Matplotlib.
`plt.title()` is used to add a title to the plot, providing context or information about the data being visualized.
Example:
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.title('Line Chart')
plt.show()
Pergunta 13. What is the role of the `plt.xticks()` and `plt.yticks()` functions in Matplotlib?
`plt.xticks()` and `plt.yticks()` are used to customize the tick positions and labels on the x-axis and y-axis, respectively.
Example:
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.xticks([1, 2, 3, 4], ['A', 'B', 'C', 'D'])
plt.show()
Pergunta 14. 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 mplot3d
fig = 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()
Pergunta 15. What is the purpose of the `plt.imshow()` function in Matplotlib?
`plt.imshow()` is used to display images in Matplotlib plots.
Example:
import matplotlib.image as mpimg
img = mpimg.imread('image.png')
plt.imshow(img)
plt.show()
Mais uteis segundo os usuarios:
- What is Matplotlib and what is its primary use?
- How can you add labels to the x-axis and y-axis in a Matplotlib plot?
- How to create a scatter plot in Matplotlib?
- What is the purpose of the `plt.tight_layout()` function in Matplotlib?
- How can you create error bars in a Matplotlib plot?