In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
 
            
                     
                
2025-10-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces Python+matplotlib how to draw stacking diagram, the article is very detailed, has a certain reference value, interested friends must read it!
I. horizontal stacking diagram
A stacked chart is actually a special form of a bar chart.
From matplotlib import pyplot as plt plt.style.use ('seaborn') plt.figure (figsize= (15Power9)) plt.rcParams.update ({' font.family': "Microsoft YaHei"}) plt.title ("China Box Office 2021TOP9") plt.bar (cnbodfgbsort.index,cnbodfgbsort.PERSONS) plt.bar (cnbodfgbsort.index,cnbodfgbsort.PRICE) plt.bar (cnbodfgbsort.index,cnbodfgbsort.points) plt.show ()
Stacking diagram effect
 
You can see that some of the blue data are obscured. If we want to show all of them, we can:
Index_x=np.arange (len (cnbodfgbsort.index)) index_xw=0.15from matplotlib import pyplot as plt plt.style.use ('classic') plt.figure (figsize= (152.9)) plt.rcParams.update ({' font.family': "Microsoft YaHei"}) plt.title ("China Box Office 2021TOP9") plt.bar (index_x,cnbodfgbsort.PERSONS,width=w) plt.bar (index_x+w,cnbodfgbsort.PRICE,width=w) plt.bar (index_x+2*w,cnbodfgbsort.points,width=w) plt.show ()
 
You can see that there is too much difference between BO, PRICE and PERSONS in the data source of Excel. If you make a stack chart, BO will overwrite all the others and cannot show a good effect:
Because the data are so different, we can directly divide BO by 1000:
From matplotlib import pyplot as plt plt.style.use ('classic') plt.figure (figsize= (15Power9)) plt.rcParams.update ({' font.family': "Microsoft YaHei"}) plt.title ("China Box Office 2021TOP9") plt.bar (cnbodfgbsort.index,cnbodfgbsort.PERSONS) plt.bar (cnbodfgbsort.index,cnbodfgbsort.PRICE) plt.bar (cnbodfgbsort.index,cnbodfgbsort.BO/1000) plt.bar (cnbodfgbsort.index,cnbodfgbsort.points) plt.show ()
From matplotlib import pyplot as plt plt.style.use ('classic') plt.figure (figsize= (15Power9)) plt.rcParams.update ({' font.family': "Microsoft YaHei"}) plt.title ("China Box Office 2021TOP9") plt.bar (index_x-w,cnbodfgbsort.BO/1000,width=w) # directly divides BO by 1000plt.bar (index_x,cnbodfgbsort.PERSONS,width=w) plt.bar (index_x+w,cnbodfgbsort.PRICE,width=w) plt.bar (index_x+2*w,cnbodfgbsort.points) Width=w) plt.show ()
2. Labels= ['war', 'love', 'animation', 'action', 'thriller', 'plot'] colors= ['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot (cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors)
Labels= ['war', 'love', 'animation', 'action', 'thriller', 'plot'] colors= ['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot (cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.BO/900,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors)
Add the data tag plt.legend () labels= ['box office', 'ticket price', 'person-times', 'score'] colors= ['tan','violet','turquoise','tomato','teal','steelblue'] plt.stackplot (cnbodfgbsort.index,cnbodfgbsort.PRICE,cnbodfgbsort.BO/900,cnbodfgbsort.PERSONS,cnbodfgbsort.points,labels=labels,colors=colors) plt.legend ()
These are all the contents of the article "how to draw a stacking Diagram for Python+matplotlib". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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: 0
*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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about

The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r


A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from

Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





 
             
            About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.