In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to customize the drawing of column chart in matplotlib, I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Import pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsdf = pd.read_excel ("D:\ my documents\ jupyter notebook.xlsx") df
Sns.set (style = "white", font_scale = 1.2) # solve Chinese garbled plt.rcParams ["font.sans-serif"] = "simhei" # set font and its size font1 = {"family": "simhei", "weight": "normal", "size": 18} # region _ pivot = pd.pivot_table (df, values= "General score", index= "course Nature" Aggfunc='count') .reset_index () .sort_values (ascending=True,by= "overall score") # set canvas size f, ax = plt.subplots (figsize= (8,6)) # draw bar graph barh = plt.barh (region_pivot ["nature of the course"] .values, region_pivot ["General score"]. Values, color='dodgerblue') barh [- 1] .set _ color ("red") # add data label for y to the bar chart X in enumerate (region_pivot ["overall score"] .values): plt.text (x + 60, y-0.1) "% s"% x) # remove the outer lines ax.spines ["right"]. Set_visible (False) ax.spines ["top"]. Set_visible (False) ax.spines ["bottom"]. Set_visible (False) ax.spines ["left"]. Set_visible (False) # ax.set (title = "sum of total scores of courses of various nature", xlabel = "total scores" Ylabel = "course nature") # set the font size of the dimension plt.tick_params (labelsize = 15) plt.xlabel ("course nature", font1) plt.ylabel ("total score", font1) plt.title ("sum of total scores of courses of various nature", font1) # Save output visualization image f.savefig (r "C:\ Users\ QDM\ Desktop\ 1.png", bbox_inches= "tight")
Sns.set (style = "white", font_scale = 1.2) # solve Chinese garbled plt.rcParams ["font.sans-serif"] = "simhei" # set font and its size font1 = {"family": "simhei", "weight": "normal", "size": 18,} # region _ pivot = pd.pivot_table (df, values = "overall score", index = "course nature" Aggfunc = "count"). Reset_index (). Sort_values (ascending = False, by= "overall score") # set canvas size f, ax = plt.subplots (figsize= (12,6)) # draw a bar chart bar = plt.bar (region_pivot ["nature of the course"]. Values, region_pivot ["overall score"]. Values, color = "dodgerblue") bar [0] .set _ color ("green") # add tag for x Y in enumerate (region_pivot ["overall score"] .values): plt.text (x-0.2, y + 60) "% s"% y) # remove all frame lines ax.spines ["right"]. Set_visible (False) ax.spines ["top"]. Set_visible (False) ax.spines ["bottom"]. Set_visible (False) ax.spines ["left"]. Set_visible (False) # ax.set (title = "sum of total evaluation scores of courses of various nature", xlabel = "nature of the course" Ylabel = "total score") plt.tick_params (labelsize = 14) plt.xlabel ("nature of the course", font1) plt.ylabel ("total score", font1) plt.title ("sum of total scores of courses of various nature", font1) f.savefig (r "C:\ Users\ QDM\ Desktop\ vertical column .png", bbox_inches = "tight")
After reading the above, have you mastered how to customize the method of drawing column chart in matplotlib? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.