In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "Python how to draw Matplotlib histogram", the explanation content in the article is simple and clear, easy to learn and understand, please follow the idea of Xiaobian slowly in-depth, together to study and learn "Python how to draw Matplotlib histogram"!
Foreword:
A histogram is a graph that uses rectangular bars to represent the distribution of data, arranged horizontally or vertically, and whose height or length is proportional to the values they represent.
Matplotlib provides bar() methods to draw histograms,
The syntax format is as follows:
plt.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)
Common parameters and descriptions are as follows:
x: represents x-axis data, receives list-type data
height: indicates the height of the histogram, receiving list type data
width: indicates the width of the histogram, receiving decimals between 0 and 1, default is 0.8
bottom: indicates the starting value of y coordinate of histogram, default is 0
align: indicates the alignment of the histogram with the x coordinate. The value is "center" or "edge". The default is "center", which means that the histogram is centered on the x coordinate. Set to "edge" to indicate that the left edge of the histogram is aligned with the x coordinate. At the same time, passing a negative width indicates that the right edge of the histogram is aligned with the x coordinate.
color: represents histogram color, can be a string or list
edgecolor: indicates the border color of the histogram, which can be a string or a list
For example, here are the popularity scores for several cities (examples):
import matplotlib.pyplot as pltx = ["beijing", "tianjin", "shanghai", "jinan"]y = [99, 88, 96, 75]plt.bar(x,y)plt.show()
The output is as follows:
If you want to draw a horizontal cylinder, you can use the barh() method,
As follows:
import matplotlib.pyplot as pltx = ["beijing", "tianjin", "shanghai", "jinan"]y = [99, 88, 96, 75]plt.barh(x,y)plt.show()
The output is as follows:
Thank you for reading, the above is "Python how to draw Matplotlib histogram" content, after the study of this article, I believe we have a deeper understanding of Python how to draw Matplotlib histogram this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.