Drawing package to use matplotlib

First, import syntax:

  import matplotlib.pyplot as plt

  %matplotlib inline

 

Second, change the font, the coordinate axis values ​​may be negative

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

  SimHei: blackbody

 

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

 

Third, add chart elements

  . 1, PLT. Figure (. 1, Figure (10,4)) figsize: length and width provided:

  . 2, PLT title ( 'This is a line graph') title: FIG name

  .. 3, PLT XTICK ([0,10,20]) XTICK: X-axis scale

  . 4, PLT. The xlabel ( 'X-axis') xlabel: x-axis named

  5, plt.show () Display

  . 6, plt.plot (np.random_intergers (-20,20,20), label = 'No1', Color = 'R & lt') random_intergers: scale range label: Name Legend color: Color

  .. 7, PLT Legend () Legend: Legend switching action

 

Fourth, the classification of the cycle to obtain multiple visualization

  for city,grouped in data.groupby('city'):

    x=grouped['mean']

    y=grouped['count']

    plt.scatter(x,y,label=city)

  plt.legend(loc='upper right')

  plt.xlabel ( '...')

  plt.ylabel ( '...')

  plt.show()

 

Fifth, the same canvas to draw more than one sub-graph

  1, plt.figure (figsize = (12,4)): setting the size of the canvas

  2, PLT. The subplot (1,2,1) is provided with several sub-graph, which currently belongs Zhang subgraph

 

Guess you like

Origin www.cnblogs.com/hankh/p/11525242.html