Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use subgraph to draw data in Matplotlib

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use subgraphs to draw data in Matplotlib. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

First, we read the data from the data.csv file and draw it:

Let's take a look at the code implementation: import pandas as pdfrom matplotlib import pyplot as pltfrom matplotlib import font_manager

Plt.style.use ('seaborn')

Data = pd.read_csv ('data.csv') ages = data [' Age'] dev_salaries = data ['All_Devs'] py_salaries = data [' Python'] js_salaries = data ['JavaScript'] # create subgraph fig, (ax1,ax2) = plt.subplots (nrows=2,ncols=1) ax1.plot (ages, dev_salaries, color='#444444', linestyle='--', label='All Devs') ax2.plot (ages, py_salaries, label='Python') ax2.plot (ages Js_salaries, label='JavaScript') zh_font = font_manager.\ FontProperties (fname='C:\\ Windows\\ Fonts\ msyh.ttf')

Ax1.legend () ax1.set_title ('average salary chart of age', fontproperties=zh_font) ax1.set_ylabel ('average salary', fontproperties=zh_font)

Ax2.legend () ax2.set_xlabel ('age', fontproperties=zh_font) ax2.set_ylabel ('average salary', fontproperties=zh_font)

Plt.tight_layout ()

Plt.show () # Save the chart as a picture fig.savefig ('fig.png')

Running result:

After reading the above, do you have any further understanding of how to use subgraphs to draw data in Matplotlib? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 237

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report