Complete the code to import the correct collection class for drawing multiple lines efficiently.
from matplotlib.collections import [1] lines = LineCollection([[(0, 0), (1, 1)], [(1, 0), (0, 1)]])
The LineCollection class is used to draw multiple lines efficiently in matplotlib.
Complete the code to create a PolyCollection from a list of polygons.
from matplotlib.collections import PolyCollection polygons = [[(0, 0), (1, 0), (0.5, 1)], [(1, 1), (2, 1), (1.5, 2)]] collection = PolyCollection([1])
The PolyCollection takes a list of polygons as input, so we pass the polygons variable.
Fix the error in the code to add a LineCollection to the axes.
import matplotlib.pyplot as plt from matplotlib.collections import LineCollection fig, ax = plt.subplots() lines = [[(0, 0), (1, 1)], [(1, 0), (0, 1)]] collection = LineCollection(lines) ax.[1](collection) plt.show()
The correct method to add a LineCollection to axes is add_collection.
Fill both blanks to create a PolyCollection with face colors and add it to the axes.
import matplotlib.pyplot as plt from matplotlib.collections import PolyCollection fig, ax = plt.subplots() polygons = [[(0, 0), (1, 0), (0.5, 1)], [(1, 1), (2, 1), (1.5, 2)]] colors = ['red', 'blue'] collection = PolyCollection([1], facecolors=[2]) ax.add_collection(collection) plt.show()
The first blank should be the list of polygons, and the second blank should be the list of colors for facecolors.
Fill all three blanks to create a LineCollection with linewidths and add it to the axes.
import matplotlib.pyplot as plt from matplotlib.collections import LineCollection fig, ax = plt.subplots() lines = [[(0, 0), (1, 1)], [(1, 0), (0, 1)]] widths = [2, 4] collection = LineCollection([1], linewidths=[2], colors='green') ax.[3](collection) plt.show()
The LineCollection is created from the list of lines, with linewidths set to widths, and added to axes using add_collection.