Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

An example Analysis of the Chart displayed in matplotlib

Shulou Source: shulou.com Published: 2022-06-02 02:59:12 09月11日 Update

Xiaobian to share with you matplotlib Chinese display of the chart example analysis, I hope you read this article after all have something to gain, let's discuss it together!

Prepare #Import Package and Configure Chinese

%matplotlib inline

import matplotlib

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.font_manager import FontProperties

# simhei.ttf can replace any Chinese ttf font, note that the path is correct

font = FontProperties(fname='simhei.ttf', size=16)

#Set matplotlib to display Chinese and minus sign normally

matplotlib.rcParams['font.sans-serif']=['SimHei']

matplotlib.rcParams['axes.unicode_minus']=False

Histogram #Generate canvas

plt.figure(figsize=(10, 6), dpi=80)

#abscissa city name

x = ['Heilongjiang',' Hongkong','Taiwan',' Shanghai','Inner Mongolia',' Shanxi','Beijing',' Shanxi','Guangdong',' Macao']

#Number of existing diagnoses on the day

y = [339, 222, 116, 54, 52, 50, 46, 37, 26, 12]

plt.bar(x,y,width=0.5)

#Title

plt.title ('2020.04.29 existing diagnoses top10', fontproperties=font)

#abscissa label

plt.xlabel ('top10 City', fontproperties=font)

#Coordinates label

plt.ylabel ('Number of existing diagnostics', fontproperties=font)

#Make coordinate scales

plt.xticks(x, fontproperties=font)

plt.show()

pie chart #generate canvas

plt.figure(figsize=(10, 6), dpi=80)

#abscissa city name

labels = ['Heilongjiang',' Hongkong','Taiwan',' Shanghai','Inner Mongolia',' Shanxi','Beijing',' Shanxi','Guangdong',' Macao']

#Number of existing diagnoses on the day

sizes = [339, 222, 116, 54, 52, 50, 46, 37, 26, 12]

explode = np.linspace(0, 0.4, 10)

plt.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=False, startangle=-45, textprops={'fontproperties':font})

plt.title("2020.04.29 Number of existing diagnoses top10 city proportion", fontproperties=font)

#Legend

plt.legend(loc='right', bbox_to_anchor=[0.75, 0.4, 0.5, 0.5], prop=font)

plt.show()

After reading this article, I believe you have a certain understanding of "matplotlib Chinese display chart example analysis," if you want to know more related knowledge, welcome to pay attention to the industry information channel, thank you for reading!

Tags: Chinese city Abscissa chart example analysis name coordinate label canvas article black dragon Shanghai Inner Mongolia Inner Mongolia Beijing Taiwan Shanxi Guangdong Macao Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Redmi NVidia Apple vpn