In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to set histogram parameters in python". In daily operation, I believe many people have doubts about how to set histogram parameters in python. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to set histogram parameters in python". Next, please follow the editor to study!
Version:python 3.6
Environment: anaconda/JupyterLab 0.27.0
Operating system: Windows 10
Import pandas as pdimport matplotlib.pyplot as plta = pd.DataFrame (train_set ['yield']. Value_counts ()). Reset_index () a.rename (columns= {'index':' yield',' yield': 'frequency'}, inplace=True) a.head () plt.figure (figsize= (24L8)) plt.bar (a [' yield'] .values, a ['frequency'] .values.round (2), color='rgb',width = 0.005 Tick_label=a ['yield'] .values.round (3) plt.xlabel (' yield', fontsize=20) plt.ylabel ('frequency', fontsize=20) plt.show ()
Add: python uses matplotlib to draw bar chart parameters to explain plt.bar ()
1. Load library import numpy as npimport matplotlib as mplimport matplotlib.pyplot as plt2 drawing Step by step set the bar () parameter def title_table (ax):''add titles and tables to the chart' ax.set_title (label=f'No. {item1}', loc='center', pad=None, fontdict= {'color':' b'}) ax.table (loc='upper right') # position of the table in the chart area colLabels= [f'{item2} args'], # column name of the table colColours= ['g'], # fill color of the cell where the column name of the table belongs to colWidths= # alignment position of the column name of each column in the table colWidths= [0.15] # width of each column of the table cellText=args, # numeric values in the table, list of lists of each row of data cellColours= [['cornsilk']] * len (args), # fill color of the cell in which the data is located in the table cellLoc='left', # alignment position of the data in the table fontsize=8) # configure the font Display mpl.rcParams ['font.sans-serif'] = [' SimHei'] # configuration axis scale value mode in Chinese Displays the negative sign mpl.rcParams ['axes.unicode_minus'] = True# definition data x = [1, 2, 3, 4, 5] y = [6, 10, 4, 5, 1] labels = list (' ABCDE') fig, axes = plt.subplots (nrows=3, ncols=3, sharex=True, sharey=True Figsize= (18,20), facecolor='cornsilk') axes = axes.ravel () I = 0ax = axes [I] # draw a column ax.bar (xxxx, the coordinate position of the # cylinder on the x axis height=y, the height of the # cylinder) args = [e] for e in ['x' 'height']] # add a title and datasheet title_table (ax) I = 1ax = axes [I] # draw a column ax.bar (xxxx, # coordinates of the cylinder on the x-axis height=y, # the height of the cylinder align='edge', # the coordinates on the x-axis and the position of the column to it) args = [e] for e in [' xcircle, 'height' 'align']] # add title and datasheet title_table (ax) I = 2ax = axes [I] # draw a histogram ax.bar (xxxx, # the coordinate position of the cylinder on the x axis height=y, # the height of the cylinder align='edge', # the coordinates on the x axis and the position color='c' of the column pair # fill color of the column) args = [[e] for e in ['Xbox,' height', 'align',' color']] # add the title and data table title_table (ax) I = 3ax = axes [I] # to the chart sub-area to draw the column ax.bar (xxxx, # the coordinate position of the cylinder on the x axis height=y, # the height of the column align='edge' # the position where the coordinates on the x axis are aligned with the cylinder color='cyan', # the filling color of the cylinder tick_label=labels, # the label name of each column) args = [[e] for e in ['xcircle,' height', 'align',' color' 'tick_label']] # add title and datasheet title_table (ax) I = 4ax = axes [I] # draw a histogram ax.bar (xxxx, # the coordinate position of the cylinder on the x axis height=y, # the height of the cylinder align='edge', # the coordinates on the x axis and the position color='blue' of the column pair # the fill color of the column tick_label=labels, # the label name of each column alpha=0.6 # the transparency of the column fill color) args = [[e] for e in ['x color, 'height',' align', 'color',' tick_label' 'alpha']] # add title and datasheet title_table (ax) I = 5ax = axes [I] # draw a histogram ax.bar (xxxx, # the coordinate position of the cylinder on the x axis height=y, # the height of the cylinder align='edge', # the coordinates on the x axis and the position color='wheat' of the column pair # the filling color of the column tick_label=labels, # the label name alpha=0.6 of each column, # the transparency of the fill color of the column width=1, # the width of the column) args = [[e] for e in ['xdye,' height', 'align',' color', 'tick_label',' alpha' 'width']] # add title and datasheet title_table (ax) I = 6ax = axes [I] # draw a histogram ax.bar (xxxx, # the coordinate position of the cylinder on the x axis height=y, # the height of the cylinder align='edge', # the coordinates on the x axis and the position color='aqua' of the column pair # the fill color of the column tick_label=labels, # the label name of each column alpha=0.6, # the transparency of the column fill color width=0.8, # the width bottom=0.2 of the column, the y-axis coordinates of the baseline of the column) args = [[e] for e in ['x], 'height',' align', 'color' 'tick_label',' alpha', 'width',' bottom'] # add title and datasheet title_table (ax) I = 7ax = axes [I] # draw a column ax.bar (xxxx, # coordinate position of the cylinder on the x-axis height=y, # height of the column align='edge' The coordinates on the x-axis and the position of the cylinder to it color='lightpink', # the filling color of the cylinder tick_label=labels, the label name of each cylinder alpha=0.6, the transparency of the filling color of the cylinder width=0.8, and the width of the cylinder bottom=0.2 # the y-axis coordinates of the cylinder baseline edgecolor='g' # the border color of the cylinder) args = [[e] for e in ['Xbox,' height', 'align',' color', 'tick_label',' alpha', 'width',' bottom' 'edgecolor']] # add title and datasheet title_table (ax) I = 8ax = axes [I] # draw a histogram ax.bar (xxxx, # the coordinate position of the cylinder on the x axis height=y, # the height of the cylinder align='center', # the coordinates on the x axis and the position color='bisque' of the column pair # fill color tick_label=labels of the cylinder, # label name alpha=0.6 of each column, # transparency width=0.8 of the fill color of the cylinder, # width bottom=0.2 of the cylinder, # y coordinate edgecolor='g', of the cylinder baseline # border color linewidth=1.5 of the cylinder # width of column border) args = [[e] for e in ['xcircle,' height', 'align',' color', 'tick_label',' alpha', 'width',' bottom', 'edgecolor',' linewidth'] # add title and data table title_table (ax) to the chart sub-area # set the layout fig.subplots_adjust (left=0) for the entire sub-area Bottom=0, right=0.9, top=1, wspace=0.1, the normalized value of the width of the blank area of the # subinterval hspace=0.2) # the normalized value of the height of the blank area of the sub-interval is over, and the study of "how to set histogram parameters for python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.