Book Image

Matplotlib 2.x By Example

By : Allen Yu, Claire Chung, Aldrin Yim
Book Image

Matplotlib 2.x By Example

By: Allen Yu, Claire Chung, Aldrin Yim

Overview of this book

Big data analytics are driving innovations in scientific research, digital marketing, policy-making and much more. Matplotlib offers simple but powerful plotting interface, versatile plot types and robust customization. Matplotlib 2.x By Example illustrates the methods and applications of various plot types through real world examples. It begins by giving readers the basic know-how on how to create and customize plots by Matplotlib. It further covers how to plot different types of economic data in the form of 2D and 3D graphs, which give insights from a deluge of data from public repositories, such as Quandl Finance. You will learn to visualize geographical data on maps and implement interactive charts. By the end of this book, you will become well versed with Matplotlib in your day-to-day work to perform advanced data visualization. This book will guide you to prepare high quality figures for manuscripts and presentations. You will learn to create intuitive info-graphics and reshaping your message crisply understandable.
Table of Contents (15 chapters)
Title Page
About the Authors
About the Reviewer
Customer Feedback

Customizing lines and markers

Lines and markers are key components found among various plots. Many times, we may want to customize their appearance to better distinguish different datasets or for better or more consistent styling. Whereas markers are mainly used to show data, such as line plots and scatter plots, lines are involved in various components, such as grids, axes, and box outlines. Like text properties, we can easily apply similar settings for different line or marker objects with the same method.


Most lines in Matplotlib are drawn with the lines  class, including the ones that display the data and those setting area boundaries. Their style can be adjusted by altering parameters in lines.Line2D. We usually set colorlinestyle, and linewidth as keyword arguments. These can be written in shorthand as cls, and lw respectively. In the case of simple line graphs, we learned in Chapter 1, Hello Plotting World! that these parameters can be parsed to the plt.plot() function: