JupyterNotebook 可视化技巧

import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt

  • 格子

    sns.set_style("whitegrid")
    
  • svg显示
    deprecated

    %config InlineBackend.figure_format = 'svg' # 
    

    新方法:

    from IPython.display import set_matplotlib_formats
    set_matplotlib_formats('svg')
    
  • svg保存

    plt.savefig('%s.pdf'%file, bbox_inches='tight')
    
  • 中文

    plt.rcParams['font.sans-serif'] = ['SimHei']
    plt.rcParams['axes.unicode_minus'] = False
    
  • 3D坐标系

    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure()
    ax = Axes3D(fig)
    ax.scatter3D(xs,ys,zs,marker='.')
    
  • 可交互的3D视图(由于某bug,所以%matplotlib notebook写两次)

    %matplotlib notebook
    %matplotlib notebook
    
    ax.scatter3D(xs,ys,zs,marker='.')
    

你可能感兴趣的:(python,可视化)