Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw Multi-factor histogram by Python

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Today Xiaobian to share with you Python how to draw multi-factor histogram related knowledge points, detailed content, clear logic, I believe most people still know too much about this knowledge, so share this article for everyone to refer to, I hope you read this article after some gains, let's learn about it together.

Drawing tutorial

1. Open Spyder software, we import the corresponding library, and generate a set of data. (When you start drawing, don't think so much first, just type the code)

##import numpy as np #Generate data package import matplotlib.pyplot as plt #Plot package #Generate a set of data x = np.arange(5)y = [1, 5, 2, 3, 7]y1 = [4, 6, 3, 5, 9]

2. Check the numbers.

print(x,y,y1)

3. Start drawing, the following is the drawing code, click it, find the feeling, at this time the shape has been formed

###plt.bar(#Set x and y x,y, #Set column width width=0.3, #Set Column Color color = "red", #Set the name of the legend label = "y") plt.bar(x+0.3,y1, width = 0.3, color = "green", label = "y1")#Set x-axis tick position plt.xticks(x+0.3/2,x) #Show legend plt.legend() #Set x label plt.xlabel(# x label name "x_names", # x Font size of label size = 12, # x Label font color color = "blue") plt.ylabel("y_names", size = 12, color = "blue")#y-axis range (x-axis range only needs to change y to x) plt.ylim(0,10)#display graph plt.show()

4. What if we have three, or more, of the two columns of factors that we're doing? Let's assume that there are three pieces of data. After changing the corresponding parameters, the plot is as follows

#Add a column of data y2 = [5,3,7,9,6]plt.bar(x,y, width=0.3, color = "red", label = "y")plt.bar(x+0.3,y1, width = 0.3, color = "green", label = "y1")#Add drawing part plt.bar(x+0.6,y2, width = 0.3, color = "blue", label = "y1")#Part to change plt.xticks(x+0.6/2,x) plt.legend() plt.xlabel("x_names", size = 12, color = "blue") plt.ylabel("y_names", size = 12, color = "blue")plt.ylim(0,10)plt.show()

5. With the hatch parameter, columns can be filled e.g. hatch = "/", in addition to other fill shapes e.g.'/',','|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, * , for example, we use this parameter to fill the column and see the effect

plt.bar(x,y, width=0.28, color = "red", label = "y", #Fill shapes hatch = "//")plt.bar(x+0.3,y1, width = 0.28, color = "green", label = "y1", #Fill shapes hatch = ". ")plt.bar(x+0.6,y2, width = 0.28, color = "blue", label = "y1", #Fill shapes hatch = "-")plt.xticks(x+0.6/2,x) plt.legend() plt.xlabel("x_names", size = 12, color = "blue") plt.ylabel("y_names", size = 12, color = "blue")plt.ylim(0,10)plt.show()

That's all for Python How to Draw Multifactor Histograms. Thank you for reading! I believe everyone has a great harvest after reading this article. Xiaobian will update different knowledge for everyone every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report