Introduction
In this tutorial, we will learn how to use the LineCollection
function in Matplotlib to efficiently draw multiple lines at once. We will see how to plot multiple lines with different colors and styles, and how to use a masked array to mask some values. We will also learn how to use the ScalarMappable.set_array
function to map an array of values to colors.
VM Tips
After the VM startup is done, click the top left corner to switch to the Notebook tab to access Jupyter Notebook for practice.
Sometimes, you may need to wait a few seconds for Jupyter Notebook to finish loading. The validation of operations cannot be automated because of limitations in Jupyter Notebook.
If you face issues during learning, feel free to ask Labby. Provide feedback after the session, and we will promptly resolve the problem for you.
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
python(("`Python`")) -.-> python/FileHandlingGroup(["`File Handling`"])
matplotlib(("`Matplotlib`")) -.-> matplotlib/BasicConceptsGroup(["`Basic Concepts`"])
matplotlib(("`Matplotlib`")) -.-> matplotlib/PlotCustomizationGroup(["`Plot Customization`"])
matplotlib(("`Matplotlib`")) -.-> matplotlib/AdvancedTopicsGroup(["`Advanced Topics`"])
python(("`Python`")) -.-> python/ControlFlowGroup(["`Control Flow`"])
python(("`Python`")) -.-> python/DataStructuresGroup(["`Data Structures`"])
python(("`Python`")) -.-> python/ModulesandPackagesGroup(["`Modules and Packages`"])
python(("`Python`")) -.-> python/DataScienceandMachineLearningGroup(["`Data Science and Machine Learning`"])
python(("`Python`")) -.-> python/FunctionsGroup(["`Functions`"])
python/FileHandlingGroup -.-> python/with_statement("`Using with Statement`")
matplotlib/BasicConceptsGroup -.-> matplotlib/importing_matplotlib("`Importing Matplotlib`")
matplotlib/BasicConceptsGroup -.-> matplotlib/figures_axes("`Understanding Figures and Axes`")
matplotlib/PlotCustomizationGroup -.-> matplotlib/line_styles_colors("`Customizing Line Styles and Colors`")
matplotlib/AdvancedTopicsGroup -.-> matplotlib/matplotlib_config("`Customizing Matplotlib Configurations`")
python/ControlFlowGroup -.-> python/for_loops("`For Loops`")
python/ControlFlowGroup -.-> python/list_comprehensions("`List Comprehensions`")
python/DataStructuresGroup -.-> python/lists("`Lists`")
python/DataStructuresGroup -.-> python/tuples("`Tuples`")
python/ModulesandPackagesGroup -.-> python/importing_modules("`Importing Modules`")
python/DataScienceandMachineLearningGroup -.-> python/numerical_computing("`Numerical Computing`")
python/DataScienceandMachineLearningGroup -.-> python/data_visualization("`Data Visualization`")
python/FunctionsGroup -.-> python/build_in_functions("`Build-in Functions`")
subgraph Lab Skills
python/with_statement -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
matplotlib/importing_matplotlib -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
matplotlib/figures_axes -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
matplotlib/line_styles_colors -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
matplotlib/matplotlib_config -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/for_loops -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/list_comprehensions -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/lists -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/tuples -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/importing_modules -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/numerical_computing -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/data_visualization -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
python/build_in_functions -.-> lab-48804{{"`Efficient Line Plotting with Matplotlib`"}}
end