Python plotting and visualization details, python Visualization
Drawing and visualization of Python
1. Enable matplotlib
IPython (IPython -- Pylab) in the most common pylab Mode)
2. The matplotlib image is located in the Figure object.
You can use plt. figure: Create a new Figure. You cannot use an empty Figure to draw a new figure, you must use add_subplot to create one or more subplot axes [0, 1]. You can use sharex and sharey to specify that subplot should have the same X or Y axis.
The padding can be modified using the subplots_adjust method of Figure. wspace and hspace are used to control the percentage of width and height and can be used as the spacing between subplot.
3. Color, label, and line type
ax.plot(x,y,'g--')
4. Scale labels and Instances
Chart decoration items. Implementation Method: Use the pyplot interface and native matplotlib API that is more object-oriented.
5. Add a legend (legend)
Legend is another important tool used to identify chart elements. The simplest way is to input the label parameter when adding suplot:
fig = plt.figure();ax = add_subplot(1,1,1) ax.plot(randn(1000).cumsum(),,'k',label='one')
6. annotation and plotting on Subplot
Annotations can be added using functions such as text, arrow, and annotate.
7. Save the chart to a file
Obtain a PNG image with a minimum white edge and a resolution of DPI.
plt.savefig('figpath.png',dpi=400,bbox_inches='tight')
Dpi points per inch and bbox_inches can be used to cut the blank area around the current chart.
8. matplotlib Configuration
By using the rc method, plt. rc ('figure ', figsize = (10, 10) Globally default image size is 10X10.
You can also write it as a dictionary:
font_options = {'family':'monospace','weight':'bold','size':'small'} plt.rc('font',**font_options)
9. Plotting functions in pandas
Line chart: bar by default; barh histogram and density chart: Series hist method, kin = 'kde' scatter chart: plt. scatter
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!