Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to create a stack diagram in Matplotlib

Shulou Source: shulou.com Published: 2022-06-01 18:38:46 10月02日 Update

Editor to share with you how to create a stack diagram in Matplotlib. I hope you will get something after reading this article. Let's discuss it together.

Example

Next, let's look at an example that shows the stack chart of the performance of three athletes at each point in time:

From matplotlib import pyplot as plt from matplotlib import rcParams# sets chart font Prevent Chinese garbled rcParams ['font.family'] =' Microsoft YaHei'rcParams ['font.sans-serif'] =' Microsoft YaHei'# set Chart style plt.style.use ('fivethirtyeight') # define timeline list minutes = [1, 2, 3, 4, 5, 6, 7, 8, 9] # define the scores of three players player1 = [8, 6, 5, 5, 4, 2, 1, 1, 0] player2 = [0, 1, 2, 2, 4, 4, 4 4] player3 = [0, 1, 1, 1, 2, 2, 3, 3, 4] labels= ['athlete 1' dagger 'athlete 2' recorder 'athlete 3'] colors = ['# 6d904filler,'# fc4f30','# 008fd5'] plt.stackplot (minutes,player1,player2,player3, labels=labels) Colors=colors) # define the lable display location plt.legend (loc= (0.07)) plt.title ("stack diagram instance") plt.tight_layout () plt.show () running effect:

After reading this article, I believe you have a certain understanding of "how to create a stack diagram in Matplotlib". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Stack athletes sports Zhongchuang three charts examples scores time articles garbled location examples fonts finished effects more styles players knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB OPPO Reno Shulou Tech Info Redmi