python - basic drawing

color selection

Color selection can be selected according to the following picture (color can be directly expressed in English: red, blue...)

insert image description here
Both uppercase and lowercase letters are acceptable. Color table link

drawing

Scatterplot

coding=utf-8

import matplotlib.pyplot as plt
#简单散点图(scatte)
years = [2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]
peoples = [100, 200, 300, 400, 500, 600, 800, 1025, 1600, 2000, 2600]
#Canvas size setting
plt.figure(figsize=(5, 5), dpi=100)
#years and peoples represent the coordinates of scattered points, c/color represents the color, s represents the area of ​​the scatter point, alpha represents the transparency, linewidths represents the edge line width of the scatter point, edgecolors represents the edge color of the scatter point
plt.scatter(years, peoples,marker='o',color='blue',s=200, alpha=1/5)
plt.show()
plt.scatter(years, peoples,c='blue',s=200, alpha=1/5)
plt.show()
insert image description here
line chart
from pylab import *
mpl.rcParams[ 'font.sans-serif'] = ['SimHei'] #Graphic display in Chinese
#x value, y value, line shape, color, transparency, line width and label (note the point - the "-" in front represents the point Connected with lines, if not, it will be in the form of scattered points)
plt.plot(years, peoples,'-
', color='#4169E1', alpha=0.8, linewidth=1, label='the number of people growing in a certain school') #Display the label,
without adding the following sentence, the label will not be displayed
plt.legend(loc="upper right")
plt.xlabel('x-axis label')
plt.ylabel('y-axis label')
plt.show()
insert image description here
pie chart
#糕图
#Data, the label corresponding to the data, the percentage retains two decimal points, and the colors color ( Choose by yourself), explode centrifugal distribution (corresponding to 2013 in the value of peolpes), pctdistance percentage label distance from the center of the circle
plt.pie(peoples,labels=years,autopct='%1.2f%%',explode=(0, 0.2 , 0,0,0,0,0,0,0,0,0), pctdistance=0.8)
plt.show()
insert image description here
bar graph
#bar
graph#bar(x, height, width=0.8, bottom=None , color=None, edgecolor=None,linewidth=None, tick_label=None, xerr=None, yerr=None,label = None, ecolor=None, align, log=False, **kwargs) plt.bar(years,
height =peoples)
plt. show()
insert image description here

Guess you like

Origin blog.csdn.net/whiteof/article/details/123825392