Matplotlib Plotting Cookbook
Format: PDF / Kindle (mobi) / ePub
Learn how to create professional scientific plots using matplotlib, with more than 60 recipes that cover common use cases
About This Book
- Learn plotting with self-contained, practical examples that cover common use cases
- Build your own solutions with the orthogonal recipes
- Learn to customize and combine basic plots to make sophisticated figures
Who This Book Is For
If you are an engineer or scientist who wants to create great visualizations with Python, rather than yet another specialized language, this is the book for you. While there are several very competent plotting packages, matplotlib is “just” a Python module. Thus, if you know some Python already, you will feel at home from the first steps on. In case you are an application writer, you won't be left out since the integration of matplotlib is covered.
What You Will Learn
- Discover how to create all the common plots you need
- Enrich your plots with annotations and sophisticated legends
- Take control of your plots and master colors, linestyle, and scales
- Add a dimension to your plots and go 3D
- Integrate your graphics into your applications
- Automate your work and generate a large batch of graphics
- Create interactive plots with matplotlib
- Combine your plots to create sophisticated visualizations
matplotlib is part of the Scientific Python modules collection. matplotlib provides a large library of customizable plots and a comprehensive set of backends. It tries to make easy things easy and hard things possible. You can generate plots, add dimensions to the plots, and also make the plots interactive with just a few lines of code with matplotlib. Also, matplotlib integrates well with all common GUI modules.
This book is a head-first, hands-on journey into matplotlib, the complete and definite plotting package for Python. You will learn about the basic plots, how to customize them, and combine them to make sophisticated figures. Along with basic plots, you will also learn to make professional scientific plots.
In this book, you will start with the common figures that are offered by most plotting packages. You will learn how to add annotations, and play with styles, colors, scales, and shapes so that you can add personality and visual punch to your graphics. You will also see how to combine several graphics. With this book you will learn how to create sophisticated visualizations with simple code. Finally, you can make your plots interactive.
After reading "matplotlib Plotting Cookbook", you will be able to create the highest quality plots.
of this, and you will not be able to try this recipe. You can find useful explanations on installing LaTeX on the LaTeX Wikibook (http://en.wikibooks.org/wiki/LaTeX/Installation). LaTeX LaTeX is a document preparation system widely used in academia. Unlike document editors such as Microsoft Word or LibreOffice Writer, a LaTeX user cannot see how the final document will look while editing it. Documents are described as a mix of text and commands stored in a plain text file. Then, LaTeX will
ticks. A ticker. Formatter object instance will generate labels for the ticks. The Formatter instance we have used here is a FixedFormatter, which will take the labels from a list of strings. We then set the x axis with our Formatter instance. For this particular example, we also use a FixedLocator to ensure that each bar is right at the middle of one tick. There's more... We have barely touched the surface of the topic; there's more, much more, about ticks. A simpler way to create bar charts
large range of the remaining data. Using polar coordinates Some phenomenon are of an angular nature. An example would be the power of a loudspeaker depending on the angle we measure it from. Polar coordinates are a natural choice to represent such data. Also, cyclic data such as annual or daily statistics can be conveniently plotted in polar coordinates. In this recipe, we are going to see how to work with polar coordinates. How to do it... Let's render a simple polar curve as follows: import
the background is shown as follows :
When viewing the webpage with a browser, the figure blends in with the tiled background as shown in the following graph. The same thing would happen in other contexts, such as when using the figure in a presentation. 128 Chapter 5 How it works... By default, pyplot.savefig() will not include
backends.backend_pdf. From this package, we just need the PdfPages object. This object represents a PDF document. ff Creates an instance of the PDF document, named pdf_pages. This is done by using the pdf_pages = PdfPages('histograms.pdf') function. ff To generate each page, it does the following: ff 136 Creates a new figure instance, with the dimensions of an A4 page. This is done by using the fig = plot.figure(figsize=(8.27, 11.69), dpi=100) function. Populates the figure with