1. What is Data Visualization
Data visualization is a key aids, often we need, our data show more clearly through visualization techniques in quantitative analysis of them, which would also help us to understand the transaction, understand the data. By visualizing the data can be more quickly found some problems in quantitative investment, more conducive to analyze and resolve them. Next we mainly use visualization tools package called - Matplotlib
it is based on Numpy tkinter and secondary development, it is a powerful Python plotting and data visualization toolkit
2, Matplotlib usage
2.1, Matplotlib drawing base
Installation:
pip install matplotlib
Reference Methods:
import matplotlib.pyplot as plt
matplotlib is in python 2D graphics library, is currently the most widely used graphics library python. Although it is huge, but we can understand and grasp a simple conceptual framework and important knowledge. Its image can be divided into the following four-layer structure.
1) canvas (Artboards): there is at the lowest level is automatically introduced matplotlib library.
2) figure (canvas): based on canvas, this layer can begin to set parameters
3) axes (sub-picture): The figure is divided into different blocks, to achieve facet Drawing
4) Chart (patterning elements): Tim member graphical information or modify axes, optimized display performance graph
2.2 drawing the basic flow
The four image structures of the above matplotlib, pyplot graphics rendering module substantially follow a process.
Import module
Introducing respective first kit. According to official certification by importing:
import numpy as np import matplotlib.pyplot as plt
Canvas and create sub-graph
First, create a blank canvas, set the size of the canvas to showcase several graphics as needed, the canvas can be divided into multiple parts. Then use object methods to complete the remaining work.
Add contents of the canvas
Drawing the body portion. Add a title, tied the time axis name and other operations and draw graphics, in no particular order, you can draw graphics, or you can add all kinds of labels, but be sure to add a legend after drawing a graph.
method | description |
---|---|
plt.title() | Set the image title |
plt.xlabel () | Setting x-axis names |
plt.ylabel () | Title Set y-axis |
plt.xlim () | Range provided the x-axis |
plt.ylim () | Set y-axis range |
plt.xticks () | Setting the x axis scale |
plt.yticks () | Set y axis scale |
plt.legend () | Provided the plot legend |
Preservation and presentation graphics
Chinese display in the chart
# The windows so provided # After setting the Chinese characters can be displayed in the graph plt.rcParams [ ' font.sans serif- ' ] = [ ' SimHei ' ] # set the font of Chinese yahei plt.rcParams [ ' axes.unicode_minus ' ] False = # error message is no longer displayed garbled
2.3, simply drawing a line in FIG.
2.4, draw a histogram of the number of movies each country or region
2.5, draw the number of films released over the years Figure
2.6, draw the number of films released over the years Figure
supplement:
When using the command line drawing matplotlib
We generated images will be displayed in the form of pop
You may operate pop charts generated
Note: Once the drawing is complete, only plt.show () once, back plt.show () does not take effect, if you want to generate charts again, you need to plt.plot / bar / pie drawing once