Reader small image

You're reading from  Mastering matplotlib

Product typeBook
Published inJun 2015
Reading LevelIntermediate
Publisher
ISBN-139781783987542
Edition1st Edition
Languages
Right arrow
Authors (2):
Duncan M. McGreggor
Duncan M. McGreggor
author image
Duncan M. McGreggor

Duncan M. McGreggor, having programmed with GOTOs in the 1980s, has made up for that through community service by making open source contributions for more than 20 years. He has spent a major part of the past 10 years dealing with distributed and scientific computing (in languages ranging from Python, Common Lisp, and Julia to Clojure and Lisp Flavored Erlang). In the 1990s, after serving as a linguist in the US Army, he spent considerable time working on projects related to MATLAB and Mathematica, which was a part of his physics and maths studies at the university. Since the mid 2000s, matplotlib and NumPy have figured prominently in many of the interesting problems that he has solved for his customers. With the most recent addition of the IPython Notebook, matplotlib and the suite of the Python scientific computing libraries remain some of his most important professional tools.
Read more about Duncan M. McGreggor

Duncan M McGreggor
Duncan M McGreggor
author image
Duncan M McGreggor

Duncan M. McGreggor, having programmed with GOTOs in the 1980s, has made up for that through community service by making open source contributions for more than 20 years. He has spent a major part of the past 10 years dealing with distributed and scientific computing (in languages ranging from Python, Common Lisp, and Julia to Clojure and Lisp Flavored Erlang). In the 1990s, after serving as a linguist in the US Army, he spent considerable time working on projects related to MATLAB and Mathematica, which was a part of his physics and maths studies at the university. Since the mid 2000s, matplotlib and NumPy have figured prominently in many of the interesting problems that he has solved for his customers. With the most recent addition of the IPython Notebook, matplotlib and the suite of the Python scientific computing libraries remain some of his most important professional tools.
Read more about Duncan M McGreggor

View More author details
Right arrow

Chapter 6. Customization and Configuration

This chapter marks a conceptual dividing line for the book. We've focused on topics such as matplotlib internals and APIs, plot interaction, high-level plotting, and the use of third-party libraries. We will continue in that vein in the first part of this chapter as we discuss advanced customization techniques for matplotlib. We will finish the chapter by discussing the elements of the advanced and lesser-known matplotlib configuration. The configuration theme will continue into the next chapter and then go beyond that into the realm of deployment. As such, this chapter will mark a transition to our exploration of matplotlib in the real world and its usage in computationally intensive tasks.

This chapter will provide an overview of the following, giving you enough confidence to tackle these in more depth at your own pace:

  • Customization

    • matplotlib styles

    • Subplots

    • Further exploration

  • Configuration

    • The matplotlib run control

    • Options in IPython

To follow along...

Customization


On the journey through the lands of matplotlib, one of the signposts for intermediate territories is an increased need for fine-grained control over the libraries in the ecosystem. In our case, this means being able to tweak matplotlib for particular use cases such as specialty scales or projections, complex layouts, or a custom look and feel.

Creating a custom style

The first customization topic that we will cover is that of the new style support introduced in matplotlib 1.4. In the previous notebook, we saw how to get a list of the available styles:

In [2]: print(plt.style.available)
        ['bmh', 'ggplot', 'fivethirtyeight', 'dark_background',
        'grayscale']

Now, we're going to see how we can create and use one of our own custom styles.

You can create custom styles and use them by calling style.use with the path or URL to the style sheet. Alternatively, if you save the <style-name>.mplstyle file to the ~/.matplotlib/stylelib directory (you may need to create it...

Configuration


We've just covered some examples of matplotlib customization. Hand in hand with this topic is that of configuration—the tweaking of predefined values to override default behaviors. The matplotlib module offers two ways to override the default values for the configuration settings—you can either run the control files, or run the control parameters that are stored in-memory to make changes to a running instance.

The run control for matplotlib

While commonly expanded to the run control, the .rc extension and -rc suffix trace their origins to 1965 and the Multics (short for Multiplexed Information and Computing Service) operating system, where rc stood for the run command. Like many software systems that were developed on UNIX- or BSD-based machines, matplotlib has an rc file where the control of matplotlib may be configured. This control is not limited to configuration files; one may also access an rc object via the matplotlib API. Each of these is covered in the following few...

Summary


In this chapter, we covered two areas of detailed customization—the creation of custom styles, as well as complex subplots. In the previous chapters, you have been exposed to the means by which you can discover more of matplotlib's functionality through its sources. It was in this context that the additional topics in customization were mentioned. With this, we transitioned into the topic of matplotlib configuration via files as well as rcParams. This is a transitional topic that will be picked up again at the beginning of the next chapter, where we will cover matplotlib deployments.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering matplotlib
Published in: Jun 2015Publisher: ISBN-13: 9781783987542
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Duncan M. McGreggor

Duncan M. McGreggor, having programmed with GOTOs in the 1980s, has made up for that through community service by making open source contributions for more than 20 years. He has spent a major part of the past 10 years dealing with distributed and scientific computing (in languages ranging from Python, Common Lisp, and Julia to Clojure and Lisp Flavored Erlang). In the 1990s, after serving as a linguist in the US Army, he spent considerable time working on projects related to MATLAB and Mathematica, which was a part of his physics and maths studies at the university. Since the mid 2000s, matplotlib and NumPy have figured prominently in many of the interesting problems that he has solved for his customers. With the most recent addition of the IPython Notebook, matplotlib and the suite of the Python scientific computing libraries remain some of his most important professional tools.
Read more about Duncan M. McGreggor

author image
Duncan M McGreggor

Duncan M. McGreggor, having programmed with GOTOs in the 1980s, has made up for that through community service by making open source contributions for more than 20 years. He has spent a major part of the past 10 years dealing with distributed and scientific computing (in languages ranging from Python, Common Lisp, and Julia to Clojure and Lisp Flavored Erlang). In the 1990s, after serving as a linguist in the US Army, he spent considerable time working on projects related to MATLAB and Mathematica, which was a part of his physics and maths studies at the university. Since the mid 2000s, matplotlib and NumPy have figured prominently in many of the interesting problems that he has solved for his customers. With the most recent addition of the IPython Notebook, matplotlib and the suite of the Python scientific computing libraries remain some of his most important professional tools.
Read more about Duncan M McGreggor