--- tags: matplotlib, python --- # [*matplotlib*](https://matplotlib.org/) --- [TOC] --- ### [_matplotlib.pyplot 圖形類別_](https://matplotlib.org/api/pyplot_summary.html) > | type | parameters | | > | --------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ---------------------------------------------------------------- | > | [plot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot) | (x, y) | 連線圖 | > | [scatter](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.scatter.html#matplotlib.pyplot.scatter) | (x, y, s, c) | 散布圖(點) | > | [polar](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.polar.html#matplotlib.pyplot.polar) | (θ, r) | 極座標 | > | [hist](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist.html#matplotlib.pyplot.hist) | (x, bins(num), range(x-min, x-max)) | 直方圖 | > | [hist2d](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hist2d.html#matplotlib.pyplot.hist2d) | (x, y, bins(shape(1, 1)), range(shape(2, 2)) | 二元直方圖 | > | [hexbin](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hexbin.html#matplotlib.pyplot.hexbin) | (x, y, gridsize) | 六角直方圖 | > | [bar](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.bar.html#matplotlib.pyplot.bar) | (x, height, width, bottom, align) | 垂直長條圖 | > | [barh](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.barh.html#matplotlib.pyplot.barh) | (y, width, height, left, align) | 水平長條圖 | > | [pie](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.pie.html#matplotlib.pyplot.pie) | (x, explode(偏移), labels, autopct(比例標籤)) | 餅圖 | > | [step](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.step.html#matplotlib.pyplot.step) | (x, y, where('pre', 'post', 'mid')) | 階梯圖 | > | [contour](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html#matplotlib.pyplot.contour) | (X,Y,Z), X.Y網格, Z高度 | 等高線圖 | > | [contourf](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contourf.html#matplotlib.pyplot.contourf) | (X,Y,Z), X.Y網格, Z高度 | 等高線圖 | > | [clabel](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.clabel.html#matplotlib.pyplot.clabel) | (cs, levels, fontsize, color) | 標記等高線(需要配合等高線圖) | > | [boxplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.boxplot.html#matplotlib.pyplot.boxplot) | (x, ) | [箱型圖](https://zh.wikipedia.org/wiki/%E7%AE%B1%E5%BD%A2%E5%9C%96) | > | [violinplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.violinplot.html#matplotlib-pyplot-violinplot) | () | [小提琴圖](https://en.wikipedia.org/wiki/Violin_plot) | ### [_matplotlib.pyplot.func_](https://matplotlib.org/api/pyplot_summary.html) > | func | parameters | description | > | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------- | ----------------- | > | _內建畫圖_ | --- | --- | > | [hlines](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hlines.html#matplotlib.pyplot.hlines) | (y, x-min, x-max) | 繪製一條水平線 | > | [vlines](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.vlines.html#matplotlib.pyplot.vlines) | (x, y-min, y-max) | 繪製一條垂直線 | > | [axhline](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axhline.html#matplotlib.pyplot.axhline) | (y, left(%), right(%)) | 繪製一條水平線 | > | [axvline](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axvline.html#matplotlib.pyplot.axvline) | (x, bottom(%), top(%)) | 繪製一條垂直線 | > | [axhspan](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axhspan.html#matplotlib.pyplot.axhspan) | (y-min, y-max, left(%), right(%)) | 填滿一個矩形 | > | [axvspan](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axvspan.html#matplotlib.pyplot.axvspan) | (x-min, x-max, bottom(%), top(%)) | 填滿一個矩形 | > | [fill_between](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.fill_between.html#matplotlib.pyplot.fill_between) | (x, y1, y2) | 填滿兩個y(x)中的空間 | > | [fill_betweenx](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.fill_betweenx.html#matplotlib.pyplot.fill_betweenx) | (y, x1, x2) | 填滿兩個x(y)中的空間 | > | [text](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text) | (x, y, str, fontdict) | 在座標上寫字 | > | [figtext](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figtext.html#matplotlib.pyplot.figtext) | (x(%), y(%), s(str), fontdict) | 比例座標上寫字 | > | _標題_ | --- | --- | > | [title](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.title.html#matplotlib.pyplot.title) | (label, fontdict, loc) | 圖片標題, loc:標題位置左中右 | > | [xlabel](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlabel.html#matplotlib.pyplot.xlabel) | (label, rotation=0, fontdict) | x 標題 | > | [ylabel](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.ylabel.html#matplotlib.pyplot.ylabel) | (label, rotation=90, fontdict) | y 標題 | > | _範圍設置_ | --- | --- | > | [xlim](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlim.html#matplotlib.pyplot.xlim) | (x-min, x-max) | x 極限 | > | [ylim](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.ylim.html#matplotlib.pyplot.ylim) | (y-min, y-max) | y 極限 | > | [axis](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.axis.html#matplotlib.pyplot.axis) | (x-min, x-max, y-min, y-max) | 圖面範圍極限(與上功能重疊) | > | [xtick](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xticks.html#matplotlib.pyplot.xticks) | (array(int), array(str), fontdict) | x 刻度, 自訂刻度文字(str) | > | [ytick](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.yticks.html#matplotlib.pyplot.yticks) | (array(int), array(str), fontdict) | y 刻度, 自訂刻度文字(str) | > | _軸設定&格線設定_ | --- | --- | > | [twinx](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.twinx.html#matplotlib.pyplot.twinx) | (None) 直接呼叫共用 [example](https://matplotlib.org/gallery/subplots_axes_and_figures/two_scales.html) | 共用x軸 | > | [twiny](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.twiny.html#matplotlib.pyplot.twiny) | (None) 直接呼叫共用 [example](https://matplotlib.org/gallery/subplots_axes_and_figures/two_scales.html) | 共用y軸 | > | [semilogx](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.semilogx.html#matplotlib.pyplot.semilogx) | () | x 軸座標指數化 | > | [semilogy](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.semilogy.html#matplotlib.pyplot.semilogy) | () | y 軸座標指數化 | > | [loglog](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.loglog.html#matplotlib.pyplot.loglog) | () | 雙座標指數化 | > | [box](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.box.html#matplotlib.pyplot.box) | (bool-True) | 外框顯示 | > | [grid](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid) | (bool-False, which('major', 'minor', 'both'), axis('both', 'x', 'y')) | 格線顯示 | > | _圖例_ | --- | --- | > | [figlegend](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.figlegend.html#matplotlib.pyplot.figlegend) | (label-array(對應圖形), shadow(立體陰影), title(標題), fontsize, loc(位置)) | 在圖上畫圖例 | > | [legend](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.legend.html#matplotlib.pyplot.legend) | (label-array(對應圖形), shadow(立體陰影), title(標題), fontsize, loc(位置)) | 在子圖上畫圖例 | ### [_matplotlib.lines.Line2D 圖形設定_](https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D) > | Line2D | value | description | > | -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- | ----------- | > | [alpha](https://matplotlib.org/api/_as_gen/matplotlib.artist.Artist.set_alpha.html#matplotlib.artist.Artist.set_alpha) | float(0~1) | 透明度(%) | > | animated | bool | 動畫 | > | antialiased`(aa)` | bool | 抗鋸齒渲染 | > | [color`(c)`](https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_color) | '0~1'(詼諧), '#XXXXXX'(色碼) | 顏色 | > | [linestyle`(ls)`](https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linestyle) | 精確定義(n起始點, (on,off,on,off)2x個), 簡寫{'-', ':', '--', '-.', 'None'} | 線條風格 | > | [linewidth`(lw)`](https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_linewidth) | num | 線寬 | > | [marker](https://matplotlib.org/api/markers_api.html?highlight=marker#module-matplotlib.markers) | {unfilled, filled, mathtext(LaTeX)}參考圖片 | 標記風格 | > | [markersize`(ms)`](https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_markersize) | num | 標記大小 | > | markeredgecolor`(mec)` | color | 標記邊緣顏色 | > | markeredgewidth`(mew)` | num | 標記邊緣寬度 | > | markerfacecolor`(mfc)` | color | 標記中心顏色 | > | [drawstyle`(ds)`](https://matplotlib.org/api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D.set_drawstyle) | {'default'(直線), 'steps', 'steps-pre', 'steps-mid', 'steps-post'} | 矩形連接方式 | > | [zorder](https://matplotlib.org/api/_as_gen/matplotlib.artist.Artist.set_zorder.html#matplotlib.artist.Artist.set_zorder) | num | Z-order圖層 | ### _fontdict 字體&圖形設定_ > | fontdict | value | description | > | ------------------- | ---------------------------------------------------------- | ------------ | > | fontsize | num | 字體大小 | > | fontweight | num | 字體粗細 | > | rotation | num | 文字角度(degree) | > | verticalalignment | {'center', 'top', 'bottom', 'baseline', 'center_baseline'} | 垂直對齊 | > | horizontalalignment | {'center', 'right', 'left'} | 水平對齊 | #### [_line-style_](https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/linestyles.html) #### [_marker_](https://matplotlib.org/gallery/lines_bars_and_markers/marker_reference.html?highlight=fontdict) #### [$LaTeX$](https://matplotlib.org/tutorials/text/mathtext.html) --- [_LaTeX字典_](https://bcc16.ncu.edu.tw/7/latex/math_tex/) > > 一般字串 : `' string '` > > LaTeX字串 : `r'$ string $'` > #### _loc code位置編碼_ > > 適用legend() > > | Location String | Location Code | > | --------------- | ------------- | > | 'best' | 0 | > | 'upper right' | 1 | > | 'upper left' | 2 | > | 'lower left' | 3 | > | 'lower right' | 4 | > | 'right' | 5 | > | 'center left' | 6 | > | 'center right' | 7 | > | 'lower center' | 8 | > | 'upper center' | 9 | > | 'center' | 10 |