Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

what is the difference between axes.patch.set… and axes.set… in matplotlib?

I just learn how to use matplotlib in python.I want to know the diffence of plot set use or not use ‘patch’.I have tried the bellow code ,from the pics they seem no differences.

import matplotlib.pyplot as plt

fig1=plt.figure(dpi=500,figsize=(10,10))
sub=fig1.add_subplot(2,2,1)
sub.patch.set_facecolor('green')
plt.show()
import matplotlib.pyplot as plt

fig1=plt.figure(dpi=500,figsize=(10,10))
sub=fig1.add_subplot(2,2,1)
sub.set_facecolor('green')
plt.show()

I have searched google but i find some people use patch while others not ,they don’t why.
I want to know the difference and how to use both forms.
Thanks a lot!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There is no difference. Axes.set_facecolor gives you a shortcut to Axes.patch.set_facecolor:

From matplotlib/axes/_base.py:

    def set_facecolor(self, color):
        """
        Set the facecolor of the Axes.


        Parameters
        ----------
        color : color
        """
        self._facecolor = color
        self.stale = True
        return self.patch.set_facecolor(color)

Note: Axes is an Artist subclass

From the documentation, click on the [source] button.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading