Python drawing and visualization details
- 2020-05-26 09:30:34
- OfStack
Drawing and visualization of Python
1. Enable matplotlib
Most commonly used Pylab mode IPython (IPython --pylab)
2. All images of matplotlib are located in the Figure object.
You can create a new Figure using plt.figure, you cannot draw through empty Figure, you must create one or more subplot axes[0,1] using add_subplot, you can specify that subplot should have the same X axis or Y axis by sharex and sharey.
The spacing can be modified using the subplots_adjust method of Figure, while wspace and hspace are used to control the percentage of width and height, and can be used as the spacing between subplot.
3. Color, marking and linestyle
ax.plot(x,y,'g--')
4. Calibration labels and examples
Chart decorator, implemented using the procedural pyplot interface and the more object-oriented native matplotlib API.
5. Add legend (legend)
Legend is another important tool for identifying diagram elements. The easiest way is to pass in the label parameter when adding suplot:
fig = plt.figure();ax = add_subplot(1,1,1)
ax.plot(randn(1000).cumsum(),,'k',label='one')
6. Notes and drawings on Subplot
Annotations can be added by functions such as text, arrow, and annotate.
7. Save the chart to a file
Get an PNG image with a minimum white edge and a resolution of 400DPI.
plt.savefig('figpath.png',dpi=400,bbox_inches='tight')
Where, dpi points per inch and bbox_inches can cut out the white space around the current chart.
8. matplotlib configuration
Using the rc method, plt.rc ('figure',figsize=(10,10)) has a global default image size of 10X10
It can also be written as a dictionary:
font_options = {'family':'monospace','weight':'bold','size':'small'}
plt.rc('font',**font_options)
9. Drawing functions in pandas
Line diagram : The default
Bar charts: bar;barh
Histogram and density diagram: Series the hist Methods, kin='kde'
Scatter diagram: plt.scatter
Thank you for reading, I hope to help you, thank you for your support of this site!