In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is a detailed introduction to "Python how to realize pie chart and coordinate system". The content is detailed, the steps are clear, and the details are properly handled. I hope this article "Python how to realize pie chart and coordinate system" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of Xiaobian.
Python visualization
#Import two libraries
import numpy as np
import matplotlib.pyplot as plt
#The first parameter is the initial value of the x axis
#The second argument is the end value of the x axis
#The third returns num uniformly distributed samples, that is, how many points are taken from the interval 0-12, if the best value for the curve is a little larger
x = np.linspace(0, 12, 50)
y = np.sin(x) #function
z = np.cos(x) #function
plt.figure(figsize=(8, 4))#explained below
plt.plot(x, y, label="$sin(x)$", color="red", linewidth=2) #Plot function images and annotations
plt.plot(x, z, "b--", label="$cos(X^2)$")# b--means dashed line
plt.xlabel("Time(s)") #name of x-axis
plt.ylabel("Volt1")
plt.title("PyPlot First Example")
#The first argument is the starting value representing the y-axis
#The second argument is the end value representing the y-axis
plt.ylim(-1.2, 1, 2)
plt.legend()
plt.show () Here I want to add a knowledge
figure syntax description
figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)
num: Image number or name, number is number, string is name
figsize: Specifies the width and height of the figure in inches;
The dpi parameter specifies the resolution of the drawing object, that is, how many pixels per inch. The default value is 80. 1 inch equals 2.5 cm. A4 paper is 21*30cm paper.
facecolor: background color
edgecolor: border color
frameon: whether to display a frame
The final rendering:
What's written above is a coordinate system.
Now let's see how the fan is drawn.
import numpy as np
import matplotlib.pyplot as plt
labels = 'A', 'B', 'C', 'D'
fracs = [15, 30.55, 44.44, 10]
explode = [0, 0, 0, 0] # 0.1 Bulge this part,
plt.axes(aspect=1) # set this , Figure is round, otherwise it is an ellipse
# autopct ,show percet
plt.pie(x=fracs, labels=labels, explode=explode, autopct='%3.1f %%',shadow=True, labeldistance=1.1, startangle=90,pctdistance=0.6)
plt.show()
labeldistance: how far the text is from the distant point, 1.1 refers to the position of 1.1 times the radius
autopct: text format inside a circle,%3.1f%% indicates a floating point number with three decimal places and one integer place
Shadow: Does the pie have a shadow?
startangle: Starting angle, 0, means turning counterclockwise from 0, which is the first block. It's usually better to start at 90 degrees.
pctdistance: percentage of text distance from center
patches, l_texts, p_texts: To get the return value of the pie chart,
p_texts: text inside the pie chart
l_texts: text outside the pie chart label
Let's see the renderings.
Read here, this article "Python how to achieve pie chart and coordinate system" article has been introduced, want to master the knowledge points of this article also need to practice to understand, if you want to know more related content of the article, welcome to 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.
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.