Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to customize the drawing of column Chart in matplotlib

Shulou Source: shulou.com Published: 2022-06-02 06:03:48 09月17日 Update

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!

Tags: General comment grade nature course size sum font garbled content method more bar label canvas question Chinese helpless for this reason picture Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia Xiaomi Apple vpn