Python图表绘制Matplotlib
引入
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# 導入相關模塊
| 使用 |
# 圖表窗口1 → plt.show() |
| 特點:使用后無需寫 show() | # 圖表窗口2 → 魔法函數,嵌入圖表
%matplotlib inline |
| # 圖表窗口3 → 魔法函數,彈出可交互的matplotlib窗口
%matplotlib notebook |
|
| # 圖表窗口4 → 魔法函數,彈出matplotlib控制臺
%matplotlib qt5 #plt.close() #plt.gcf().clear() |
|
| 圖標的基礎元素 | 圖名、圖裂、軸標簽、軸邊界、軸刻度、軸刻度標簽 |
|
plt.title('全國人大代表季度考核') #標題 list.plot(figsize=(6,4)) 圖標的大小 plt.legend(loc='best') #圖裂的位置 best 自適應 |
|
| 完整演示 |
import numpy as np import warnings ts.plot(kind='line', 創建 子圖 fig,axes = plt.subplots(4,1,figsize = (10,10)) s.plot(kind='bar',color = 'k',grid = True,alpha = 0.5,ax = axes[0]) # ax參數 → 選擇第幾個子圖 df.plot(kind='bar',ax = axes[1],grid = True,colormap='Reds_r') plt.figure(figsize=(10,4)) #plt.grid(True, linestyle = "--",color = "gray", linewidth = "0.5",axis = 'x') # 網格 |
幾種類型:
記住幾個點就行
|
在matplotlib中,整個圖像為一個Figure對象 在Figure對象中可以包含一個或者多個Axes對象 每個Axes(ax)對象都是一個擁有自己坐標系統的繪圖區域 plt.figure, plt.subplot #創建一個容器 盒子 fig = plt.figure(figsize=(10,6),facecolor = 'gray') #容器添加子圖 第幾行第幾個 ax1 = fig.add_subplot(2,2,1) # 第一行的左圖 |
總結
以上是生活随笔為你收集整理的Python图表绘制Matplotlib的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java基础—流
- 下一篇: SGU 242. Student'