Matplotlib 3.0 Cookbook

Book Description

Build attractive, insightful, and powerful visualizations to gain quality insights from your data

Key Features

  • Master Matplotlib for data visualization
  • Customize basic plots to make and deploy figures in cloud environments
  • Explore recipes to design various data visualizations from simple bar charts to advanced 3D plots

Book Description

Matplotlib provides a large library of customizable plots, along with a comprehensive set of backends. Matplotlib 3.0 Cookbook is your hands-on guide to exploring the world of Matplotlib, and covers the most effective plotting packages for Python 3.7.

With the help of this cookbook, you'll be able to tackle any problem you might come across while designing attractive, insightful data visualizations. With the help of over 150 recipes, you'll learn how to develop plots related to business intelligence, data science, and engineering disciplines with highly detailed visualizations. Once you've familiarized yourself with the fundamentals, you'll move on to developing professional dashboards with a wide variety of graphs and sophisticated grid layouts in 2D and 3D. You'll annotate and add rich text to the plots, enabling the creation of a business storyline. In addition to this, you'll learn how to save figures and animations in various formats for downstream deployment, followed by extending the functionality offered by various internal and third-party toolkits, such as axisartist, axes_grid, Cartopy, and Seaborn.

By the end of this book, you'll be able to create high-quality customized plots and deploy them on the web and on supported GUI applications such as Tkinter, Qt 5, and wxPython by implementing real-world use cases and examples.

What you will learn

  • Develop simple to advanced data visualizations in Matplotlib
  • Use the pyplot API to quickly develop and deploy different plots
  • Use object-oriented APIs for maximum flexibility with the customization of figures
  • Develop interactive plots with animation and widgets
  • Use maps for geographical plotting
  • Enrich your visualizations using embedded texts and mathematical expressions
  • Embed Matplotlib plots into other GUIs used for developing applications
  • Use toolkits such as axisartist, axes_grid1, and cartopy to extend the base functionality of Matplotlib

Who this book is for

The Matplotlib 3.0 Cookbook is for you if you are a data analyst, data scientist, or Python developer looking for quick recipes for a multitude of visualizations. This book is also for those who want to build variations of interactive visualizations.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Matplotlib 3.0 Cookbook
  3. Packt Upsell
    1. Why subscribe?
    2. Packt.com
  4. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Get in touch
      1. Reviews
  6. Anatomy of Matplotlib
    1. Introduction
      1. Architecture of Matplotlib
        1. Backend layer
        2. Artist layer
        3. Scripting layer
      2. Elements of a figure
        1. Figure
        2. Axes
        3. Axis
        4. Label
        5. Legend
        6. Title
        7. Ticklabels
        8. Spines
        9. Grid
    2. Working in interactive mode
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Working in non-interactive mode
      1. How to do it...
      2. How it works...
    4. Reading from external files and plotting
      1. Getting ready
      2. How to do it...
        1. Reading from a .txt file
        2. Reading from a .csv file
        3. Reading from an .xlsx file
        4. Plotting the graph
      3. How it works...
    5. Changing and resetting default environment variables 
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  7. Getting Started with Basic Plots
    1. Introduction
    2. Line plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Bar plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Scatter plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Bubble plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Stacked plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Pie plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Table chart
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Polar plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    10. Histogram
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Box plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    12. Violin plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Reading and displaying images
      1. Getting ready
      2. How to do it...
      3. How it works...
    14. Heatmap
      1. Getting ready
      2. How to do it...
      3. How it works...
    15. Hinton diagram
      1. Getting ready
      2. How to do it...
      3. How it works...
    16. Contour plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    17. Triangulations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    18. Stream plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    19. Path
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Plotting Multiple Charts, Subplots, and Figures
    1. Introduction
    2. Plotting multiple graphs on the same axes
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Plotting subplots on the same figure
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Plotting multiple figures in a session
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Logarithmic scale
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Using units of measurement
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  9. Developing Visualizations for Publishing Quality
    1. Introduction
    2. Color, line style, and marker customization
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Working with standard colormaps
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. User-defined colors and colormaps
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Working with legend
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Customizing labels and titles
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Using autoscale and axis limits
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Customizing ticks and ticklabels
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Customizing spines
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Twin axes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    11. Using hatch
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Using annotation
      1. Getting ready
      2. How to do it...
      3. How it works...
    13. Using style sheets
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  10. Plotting with Object-Oriented API
    1. Introduction
    2. Plotting a correlation matrix using pyplot and object-oriented APIs
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Plotting patches using object-oriented API
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Plotting collections using object-oriented API
      1. Getting ready
      2. How to do it...
      3. How it works...
  11. Plotting with Advanced Features
    1. Using property cycler
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    2. Using Path effects
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using transforms
      1. Transforming data co-ordinates to display co-ordinates
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      2. Using axes and blended co-ordinate system transforms
        1. Getting ready
        2. How to do it...
        3. How it works...
    4. Taking control of axes positions
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. GridSpec for figure layout
      1. Using GridSpec
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      2. GridSpec alignment
        1. Getting ready
        2. How to do it...
        3. How it works ...
      3. Constrained layout
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Using GridSpecFromSubplotSpec
        1. Getting ready
        2. How to do it...
        3. How it works...
    6. Using origin and extent for image orientation
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Geographical plotting using geopandas
      1. Getting ready
      2. How to do it...
      3. How it works...
  12. Embedding Text and Expressions
    1. Introduction
    2. Using mathematical expressions with a font dictionary
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Annotating a point on a polar plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using ConnectionPatch
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using a text box
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Plotting area under an integral curve
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Defining custom markers
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Fractions, regular mathematical expressions, and symbols
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    9. Word embeddings in two dimensions
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Saving the Figure in Different Formats
    1. Introduction
    2. Saving the figure in various formats
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Avoiding truncation while saving the figure
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Saving partial figures
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Managing image resolution
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Managing transparency for web applications
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Creating multi-page PDF reports
      1. Getting ready
      2. How to do it...
      3. How it works...
  14. Developing Interactive Plots
    1. Introduction
    2. Events and callbacks
      1. Exception handling
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      2. Key press and release events
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Mouse button press event
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Motion notify and mouse button press events
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Pick event
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Figure and axes, enter and leave events
        1. Getting ready
        2. How to do it...
        3. How it works...
      7. Using twin axes for plotting four temperature scales
        1. Getting ready
        2. How to do it...
        3. How it works...
    3. Widgets
      1. Cursor
        1. Getting ready
        2. How to do it...
        3. How it works...
      2. Buttons
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Check buttons
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Radio buttons
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Textbox
        1. Getting ready
        2. How to do it...
        3. How it works...
    4. Animation
      1. Animated sigmoid curve
        1. Getting ready
        2. How to do it...
        3. How it works...
      2. Saving the animation to an mp4 file
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Exponentially decaying tan function
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Animated bubble plot 
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Animating multiple line plots
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Animation of images
        1. Getting ready
        2. How to do it...
        3. How it works...
  15. Embedding Plots in a Graphical User Interface
    1. Introduction
      1. Interface between the Matplotlib and GUI applications
    2. Using the Slider and Button Widgets of Matplotlib
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Using the Slider and Button widgets of Tkinter GUI 
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Embedding Matplotlib in a Tkinter GUI application
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using the Slider and Button widgets of WxPython GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Embedding Matplotlib in to a wxPython GUI application
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using the Slider and Button widgets of Qt's GUI
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Embedding Matplotlib in to a Qt GUI application
      1. Getting ready
      2. How to do it...
      3. How it works...
  16. Plotting 3D Graphs Using the mplot3d Toolkit
    1. Introduction
    2. Line plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Scatter plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Bar plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Polygon plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    6. Contour plot
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Surface plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Wireframe plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Triangular surface plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Plotting 2D data in 3D
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. 3D visualization of linearly non-separable data in 2D
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Word embeddings
      1. Getting ready
      2. How to do it...
      3. How it works...
  17. Using the axisartist Toolkit
    1. Introduction
    2. Understanding attributes in axisartist
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Defining curvilinear grids in rectangular boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Defining polar axes in rectangular boxes
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using floating axes for a rectangular plot
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating polar axes using floating axes
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Plotting planetary system data on floating polar axes
      1. Getting ready
      2. How to do it...
      3. How it works...
  18. Using the axes_grid1 Toolkit
    1. Introduction
    2. Plotting twin axes using the axisartist and axesgrid1 toolkits
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Using AxesDivider to plot a scatter plot and associated histograms
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using AxesDivider to plot a colorbar
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using ImageGrid to plot images with a colorbar in a grid
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using inset_locator to zoom in on an image
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using inset_locator to plot inset axes
      1. Getting ready
      2. How to do it...
      3. How it works...
  19. Plotting Geographical Maps Using Cartopy Toolkit
    1. Introduction
    2. Plotting basic map features
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Plotting projections
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Using grid lines and labels
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Plotting locations on the map
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Plotting country maps with political boundaries
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Plotting country maps using GeoPandas and cartopy
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Plotting populated places of the world
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Plotting the top five and bottom five populated countries
      1. Getting ready
      2. How to do it...
      3. How it works...
    10. Plotting temperatures across the globe
      1. Getting ready
      2. How to do it...
      3. How it works...
    11. Plotting time zones
      1. Getting ready
      2. How to do it...
      3. How it works...
    12. Plotting an animated map
      1. Getting ready
      2. How to do it...
      3. How it works...
  20. Exploratory Data Analysis Using the Seaborn Toolkit
    1. Introduction
      1. Snacks Sales dataset
      2. Wine Quality
      3. Semantic and facet variables
    2. Relational plots
      1. Line plots with one-to-one and one-to-many relationships
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      2. Line plots with a long-form dataset
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Scatter plots
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    3. Categorical plots
      1. Strip and swarm plots
        1. Getting ready
        2. How to do it...
        3. How it works...
      2. Box and boxn plots
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Bar and count plots
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Violin plots
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Point plots
        1. Getting ready
        2. How to do it...
        3. How it works...
    4. Distribution plots
      1. distplot()
        1. Getting ready
        2. How to do it...
        3. How it works...
      2. kdeplot()
        1. Getting ready
        2. How to do it...
        3. How it works...
    5. Regression plots
      1. regplot() and residplot()
        1. Getting ready
        2. How to do it...
        3. How it works...
      2. lmplot()
        1. Getting ready
        2. How to do it...
        3. How it works...
    6. Multi-plot grids
      1. jointplot() and JointGrid()
        1. Getting ready
        2. jointplot()
          1. How to do it...
          2. How it works...
        3. JointGrid()
          1. How to do it...
          2. How it works...
      2. pairplot() and PairGrid()
        1. Getting ready
        2. pairplot()
        3. How to do it...
        4. How it works...
        5. PairGrid()
        6. How to do it...
        7. How it works...
      3. FacetGrid()
        1. Getting ready
        2. How to do it...
        3. How it works...
    7. Matrix plots
      1. Heatmaps
        1. Getting ready
        2. How to do it...
        3. How it works...
      2. Clustermaps
        1. Getting ready
        2. How to do it...
        3. How it works...
  21. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product Information

  • Title: Matplotlib 3.0 Cookbook
  • Author(s): Srinivasa Rao Poladi
  • Release date: October 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781789135718