Python data analysis of pandas data visualization line chart bar chart pandas drawing garbled solution

Python data analysis of pandas data visualization line chart bar chart pandas drawing garbled solution

Python data visualization commonly used matplotlib library, matplotlib is the underlying library, today I learned pandas data visualization, compared to matplotlib library, much simpler.

line chart

%matplotlib inline
import numpy as np
import pandas as pd
x1 = pd.Series(np.random.normal(size=10))
x1.plot()

We can also add grid parameters to add grids:

x1.plot(grid=True)

Bar graph

Take the short book data from the previous article as an example:

jianshu.groupby(jianshu.index)[['view']].sum().sort(['view'],ascending=False)[0:5].plot(kind='bar')
jianshu.groupby(jianshu.index)[['gain']].sum().sort(['gain'],ascending=False)[0:10].plot(kind='barh')

pandas drawing garbled solution

Pandas drawing is actually inherited from the matplotlib library, and the matplotlib library defaults to ASCII encoding, so the Chinese drawing will be garbled. We need to go to the matplotlibrc file in the matplotlib library to set it up.

Open the matplotlibrc file, uncomment the following line, and add SimHei after the colon in font.sans-serif, which is a Chinese font. Just restart python.

font.family: sans-serif
font.sans-serif: SimHei
axes.unicode_minus 
Reference: https://cloud.tencent.com/developer/article/1155581 Python data analysis of pandas data visualization line chart bar chart pandas drawing garbled solution-Cloud + Community-Tencent Cloud