I. Concept note
Bar chart (bar chart), from the same horizontal coordinates, with different numerical size to set the height of the bar, and thus represent the disorder or order of the qualitative data between the size of a quantitative indicator relationship.
The schematic is shown below:
(1) In the case of unorganized transverse coordinates, we often arrange the values in descending order of magnitude.
(2) Bar graphs can have both positive and negative vertical coordinates, but they must be plotted starting from the 0 line of the datum, otherwise they will convey incorrect visual information.
(3) When there are large differences in values between categories/more categories/longer category naming text, we can consider reversing the bar chart by 90°, i.e., using a bar chart.
(4) If the data in hand is a two-dimensional qualitative situation, you can choose stacked bar charts or side-by-side bar charts, respectively, according to demand.
① Stacked histograms:
--- Comparison of the total number of broad categories of concern 0-4
--- Also focusing on the weight of subcategory a/b in relation to the broader category
② Side-by-side bar graph (case object)
--- More attention to small class series 1-3 in comparison to different large classes 1-4
--- Concerned about differences in the distribution of values of small categories among large categories
--- line graphs can be added if information on broad aggregate categories is to be presented
II. Data presentation
In this case, we are looking to use python coding to plot side-by-side histograms using one of the matplotlib packages, so we need two-dimensional ordinal data.
According to the rest of my column, I continue to use eight randomly selected cities in order to see how the number of elementary, middle, and high schools in the eight cities compares (bars), and how the population is doing (lines).
Adhering to the principle that if there is something in the City Statistical Bulletin, it should be recorded, and if there is nothing, it should be Baidu, we have obtained the following data for mapping purposes only.
The data in the above excel sheet is stored separately and we import it using the following code
import pandas as pd school_num = (pd.read_excel('. /number of primary, junior and senior schools.xlsx')) people_num = (pd.read_excel('. /2020CensusData.xlsx'))
III. Image drawing
import as plt import matplotlib as mpl import numpy as np # Chinese and plus/minus sign settings ["-serif"] = ["SimHei"] ["axes.unicode_minus"] = False x = (8) bar_width = 0.3 tick_label = school_num['The City'] (figsize=(13,7)) # Cylindrical (x, school_num['Primary school'], bar_width, align="center", color="#2bb179", label='Primary', alpha=0.5) (x+bar_width, school_num['Middle School'], bar_width, color="b", align="center", label="Middle school.", alpha=0.5) (x+bar_width*2, school_num['High School'], bar_width, color="orange", align="center", label="High school.", alpha=0.5) # Folding lines (x+bar_width, people_num['Number of people - 10,000'], color="#ff796c", marker='o', lw=2,label='Census Count (in millions)') text_x = [x,x+bar_width,x+bar_width*2] text_x = [text_x[i][j] for i in range(3) for j in range(8) ] text_y = [school_num['Primary school'],school_num['Middle School'],school_num['High School']] text_y = [text_y[i][j] for i in range(3) for j in range(8) ] (x+bar_width, tick_label,fontsize=18) (fontsize=18) ("The City.",fontsize=20) ("Number of schools",fontsize=20) (fontsize=16) () # Columns plus numbers for x,y,text in zip(text_x,text_y,text_y): (x-0.12,y+15,str(text),fontsize=12) # (r'. /side-by-side bar chart example.png')
(Horizontal Position, Column Value) --- Horizontal position is generally obtained using (Number of Horizontal Categories), so in side-by-side, for each sub-category, move the window width right by one unit, or add 0.1 to keep them slightly apart if you think they look dense right next to each other.
For the horizontal coordinates I chose x+bar_width because we have three columns and I want the origin of the fold line to be centered corresponding to the horizontal coordinates.
--- This section adds text to the entire image, but you need to specify exactly where to add it.
(Former name, new name)
Plotting results:
I hope this helps.
summarize
to this article on the use of matplotlib to draw side-by-side bar graphs to this article, more related matplotlib to draw side-by-side bar graphs content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future!