Python Visual Learning: A detailed introduction to the Matplotlib configuration

Source: Internet
Author: User
Tags border color

Matplotlib is an excellent visual library that provides a rich interface that makes Python's visualization very easy to get started with. This series is I learn python visual learning notes, mainly for monitoring their own progress, but also want to communicate with the relevant Bo friends.
Since I am an in-service data analyst rather than a developer, learning Python visualization is primarily to solve the problem of automatic visualization of data encountered during daily work. Therefore, the study plan is to start from the basis (master do not spray), the use of books for the "Python visual Programming Practice" this book. The whole study plan is to follow this book over and over again, then check the manual or search for a specific solution based on the problems encountered during the actual use.

As the first chapter of this series, I focus on the configuration and content of Matplotlib.

1. Configuration of Matplolib default parameters

    • Many of the parameters of the Matplotlib are configured with the. rc file, and the default values have been configured for most of the properties. You can make the necessary adjustments to the various default attributes according to your needs.

    • During code execution, you can change the parameters of the run in two ways.

      • Use the dictionary (rcparams) to configure parameters: Call Rcparams (a dictionary) to adjust the corresponding parameters in the dictionary while the code is running.

      • Call the Matplotlib.rc () function: Modify the configuration item by passing in the attribute tuple to matplotlib.rc ().

      • If you need to configure dynamic modified configuration parameters, you can call Matplotlib.rcdefaults () to reset the configuration to a standard configuration.
        The following two sections of code implement the same effect, but differ in the way they are used:

        # Examples of matplotlib.rcparams used: Import matplotlib as mplmpl.rcparams[' Lines.width ']=2 #将线宽设置为2mpl. rcparams[' Lines.color ']= ' r ' #将线的颜色设置为红色 red# using matplotlib.rc () example mpl.rc (' lines ', linewidth=2,color= ' R ')

2. Configure the Matplotlib parameter for the project

The way you use configuration parameters is to allow you to use different parameter configurations in different projects, assigning configuration templates between different colleagues and projects.
The MATPLOTLIB is configured via the Matplotrc file, which can have three levels depending on the scope of their application:

    1. Current working directory: The directory in which the code runs, you can customize Matplotlib configuration items for the current project code contained in the catalog. The name of the configuration file is: MATPLOTLIBRC

    2. User-level profile:. matplotlib/matplotlibrc file. This is typically in the user's $home (that is, the documents and setting\ directory in the Windows system). You can call the Matplotlib.get_configdir () command to get the current user's profile directory.

    3. Installation-level profile: Typically in Python's site-packags directory. However, each time you reinstall Matplotlib, this file will be overwritten, so if you want to maintain a durable and efficient configuration, it is best to configure it in a user-level profile. The


      configuration file includes the following options (objects):

    • Axes: Sets the axis boundary and color, the size of the coordinate scale values, and the display of the grid;

    • Backend: Sets the target output Tkagg and Gtkagg.

    • Figure: Controls the DPI, border color, graphics size, and sub-region (subplot) settings.

    • Font: Set of fonts (font-family), font size, and style settings.

    • Grid: Sets the color and linetype of the grid.

    • Legend: Sets how the legend and the text in it are displayed.

    • Line: Sets the lines (color, linetype, lineweight, etc.) and marks.

    • Patch: A graphic object that fills 2D of space, such as polygons and circles. Controls line widths, color and antialiasing settings, and more.

    • Savefig: You can set separate settings for saved graphics, such as the color background color of the picture that renders the output as white.

    • Text: Sets the color of the font, text parsing, and so on.

    • VERBOSE: Set matplotlib information output during execution, such as silent, helpful, debug, etc.

In fact, these objects are separate objects in matplotlib, each with a separate API. In the process of matplotlib drawing, it is actually stacking all kinds of objects that are well-configured.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.