1. FIG polyline: plt.plot
- Setting data : plt.plot (x, y), y-axis single default data into, when x-axis data corresponding to the default gradually incremented from 0
- Set Color : plt.plot (x, y, color / c = ""), RGB color list is: xkcd.com/color/rgb/
- Setting data point shape : plt.plot (x, y, marker = ""), the reference symbols: matplotlib.org/api/markers...
- Cable set style : plt.plot (x, y, linestyle / ls = "")
- '-' or 'solid' ——solid line
- '--' or 'dashed' ——dashed line
- '-.' or 'dashdot' ——dash-dotted line
- ':' or 'dotted' ——dotted line
- 'None'/' '/'' ——draw nothing
- Other settings : width -linewidth / lw = n; spot size -markersize = m; transparency -alpha = m; label = 'XXX ' is used to set the label (must plt.legend (loc = "upper left" ) to display label)
- Color dot lines at the same settings : "ro-"
- While drawing a plurality of lines : plt.plot (x1, y1, " ro", x2, y2, "b0")
2. Scatter: plt.scattor
- Setting data : plt.scatter (x, y), you must pass x, y
- Size set point : plt.scatter (x, y, s ), s is the one-dimensional array representing the dot size, default is 20 unified
- Set Color :
- May be c = 'X' is provided a single color,
- Can also be used 'c = seq' such that the same color point corresponding to the same position in the sequence number, this time can cmap = 'XXX' to set the color mode. Below, a third point of the same figure, the same color
- Or simply c = [ 'r', 'b' ...] to set a different color
- cmap color mode using the reference links: matplotlib.org/examples/co...
- Shape setting data points : the same plot
- Other settings : width -linewidth / lw = n; spot size -markersize = m; transparency -alpha = m; edge color -edgecolor = X; label = 'XXX ' is used to set the label (must plt.legend (loc = "upper left") to display the label)
3. Histogram: plt.bar
- Setting data : plt.bar (x, y), must pass x, y, x represents a position of each column, y represents the height
- Setting column width : plt.bar (x, y, width ), width set the width, the default 0.8
- 设置颜色:可以用color/facecolor='X'设置单个颜色,也可以用'color=['r','b'...]'设置多个颜色。颜色参考:xkcd.com/color/rgb/
- 其它设置:线宽-linewidth/lw=n;透明度-alpha=m;边缘颜色-edgecolor=X;基座高度-bottom=0.2;label='XXX'用于设置标签(必须使用plt.legend(loc="upper left")来显示标签)
4. 直方图:plt.hist
- 设置数据:plt.hist(x,bins),必须传入x,y,x为数据;y为柱形个数,可以为'auto'
- 频数/频率图:density=True默认为频率/False频数
- 设置数据范围:range=(a,b),限定数据范围
- 柱子间隙:rwidth=n,默认为0
- 设置柱形宽度:plt.bar(x,y,width),width设置宽度,默认0.8
- 设置颜色:可以用color/facecolor='X'设置单个颜色。颜色参考:xkcd.com/color/rgb/
- 其它尺寸:线宽-linewidth/lw=n;透明度-alpha=m;边缘颜色-edgecolor=X;label='XXX'用于设置标签(必须使用plt.legend(loc="upper left")来显示标签)
5. 箱线图:plt.boxplot
- 设置数据:plt.boxplot(x) ,x为多列数据-[列1,列2...]
- 设置箱型:plt.boxplot(x,notch=),notch默认为false,长方形;False是指在50%位显示缺口,缺口越大,数*据越分散
- 设置横向纵向:plt.boxplot(x,vert=),vert默认True,垂直状态;False显示横向
- 设置最大最小值:plt.boxplot(x,whis=[n,m]),whis=[25,85],表示限度在25%到85%之间,即顶端横线的位置
- 设置箱体宽度:widths=
- 设置箱体填充:patch_artist=True
- 设置各箱型名称:labels=[1,2,3...]
- 每个箱型填充不同颜色:需遍历填充,bplot[boxes]取到各个箱型,遍历填充
6. 其它设置
- 设置坐标轴范围:plt.axis([xmin, xmax, ymin, ymax]) ,四个参数必须同时包括
- 设置xy坐标轴名称:plt.x/ylabel("XXX")
- 设置图表标题:plt.title("XXX")
- 显示网格:plt.grid(True)
- 同一张子图上绘制:plt.plot(ax=ax1))
- 直接用dataframe绘图:df.plot(x=,y=,kind=,label=)
- 对某点设置注释:plt.annotate('注释内容',xy=(被标注点坐标),xytext=(内容文本坐标),arrowprops= dict(width=箭头方块宽度, headwidth=箭头尖宽度, headlength=箭头尖长度, shrink=收缩比例,越大越短, facecolor=箭头颜色 ))
7. 绘图步骤
- 设置画板:
plt.figure( num-画板编号,默认逐渐递增;
figsize(a,b)-画板尺寸;
dpi分辨率,默认100; facecolor-背景颜色,默认白;
edgecolor-边框颜色,默认白;
frameon=True是否显示绘图框, clear=False是否清楚已存在的同名图)
- 设置单个子图:ax1=plt.subplot(221),ax2=plt.subplot(222)
- sharex/y=True表示所有子图使用相同的x/y刻度
- 同时创建多个子图:axes/((ax1,ax2),(ax3,ax4))=plt.subplots(2,1,sharex=True),axes[0,1]...
- Draw anywhere : ax1 = fig.add_axes ([left, bottom, width, height],), left, bottom located a few percent represents the drawing board; width, height represents the number representing the width and height of Artboards
- FIG sub-set title, tags : ax1.set_title ( "XXX"); ax1.set_xlable () plt.subplot2grid formula :
ax1=plt.subplot2grid((3, 3), (1, 0),colspan=2,rowspan=1)
3 represents a set drawing area of a line 3, in the second row, the first row position starts drawing span column 2, row 1 span
- GridSpec type :
import matplotlib.gridspec as gridspec
gs = gridspec.GridSpec(3, 3)
ax7 = plt.subplot (gs [1,: 2]), accounting for all the columns denote the subgraph of the front row 2 and 3,
ax10 = plt.subplot (gs [-1, -2]), represents a sub-picture representing penultimate row 1 and column 2 countdown.
- Set the font size
ax = plt.subplot (111) Sets the scale font size: plt.xticks (fontsize = 20); plt.yticks (fontsize = 20) disposed coordinate tab font size: ax.set_xlabel (..., fontsize = 20); ax .set_ylabel (..., fontsize = 20) set the font size Legend: ax.legend (..., fontsize = 20)
No public concern, faster for the latest information.