The install Matplotlib

  • The command
python -m pip install --user matplotlib
Copy the code

Draw line chart

  • Python code

    Import matplotlib.pyplot as PLT # solve the problem of saving image with negative sign '-' displayed as square, or convert negative sign to string plt.rcparams ['font. Sans-serif '] = ['SimHei'] Plt.rcparams [' font-serif '] = ['SimHei'] plt.rcparams ['axes. Unicode_minus '] = False # add input values and output values input_values = [1,2,3,4,5] squalres = [1,4,9,16,25] Ax. plot(input_values,squalres, plots) Linewidth = 3) ax.set_title(" square ", fontsize = 24); Ax.set_xlabel (" value ", fontsize = 14); Ax.set_ylabel (" value squared ", fontsize = 14); Ax.tick_params (axis = 'both', labelsize = 14) # Open the viewer to display the drawn icon plt.show()Copy the code

Three rendering

Four drawing process may encounter problems

  • The naming problem file cannot be named as matplotlib.py, otherwise an error will be reported if the class library is not imported

  • Chinese format programming box because the Chinese format is not compatible, through the next year this code rewrite configuration can be solved

    RcParams ['font. Serif '] = ['SimHei'] plt.rcparams ['font. Serif '] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = FalseCopy the code

Five epilogue

I have to say that data visualization in Python is much faster than Java, and Python is really great for data analysis