How to add black border to matplotlib 2.0 `ax` object In Python 3?

前端 未结 3 1484
别那么骄傲
别那么骄傲 2021-02-14 14:14

I\'ve been using style sheets in matplotlib lately. I really like how clean the seaborn-white looks and I want to be able to add the border to other s

3条回答
  •  逝去的感伤
    2021-02-14 15:02

    The difference between the seaborn-whitegrid and the seaborn-white styles are

    seaborn-whitegrid

    axes.grid: True
    axes.edgecolor: .8
    axes.linewidth: 1
    

    seaborn-white

    axes.grid: False
    axes.edgecolor: .15
    axes.linewidth: 1.25
    

    The following will thus provide identical plots:

    import matplotlib.pyplot as plt
    import pandas as pd
    import numpy  as np
    from collections import *
    
    Se_data = pd.Series(Counter(np.random.randint(0,10,100)))
    with plt.style.context("seaborn-whitegrid"):
        plt.rcParams["axes.edgecolor"] = "0.15"
        plt.rcParams["axes.linewidth"]  = 1.25
        fig, ax = plt.subplots()
        Se_data.plot(kind="barh", ax=ax, title="No Border")
    with plt.style.context("seaborn-white"):
        plt.rcParams["axes.grid"] = True
        fig, ax = plt.subplots()
        Se_data.plot(kind="barh", ax=ax, title="With Border")
    

提交回复
热议问题