How to make matplotlib graphs look professionally done like this?

前端 未结 4 1549
失恋的感觉
失恋的感觉 2021-01-30 23:56

Default matplotlib graphs look really unattractive and even unprofessional. I tried out couple of packages include seaborn as well as prettyplotlib but both of these just barely

4条回答
  •  爱一瞬间的悲伤
    2021-01-31 00:40

    To get closer to the style you prefer, you could use the whitegrid style in seaborn. As the other answers have noted, you control the transparency of the fill with the alpha parameter to fill_between.

    import numpy as np
    import seaborn as sns
    import matplotlib.pyplot as plt
    sns.set_style("whitegrid")
    
    blue, = sns.color_palette("muted", 1)
    
    x = np.arange(23)
    y = np.random.randint(8, 20, 23)
    
    fig, ax = plt.subplots()
    ax.plot(x, y, color=blue, lw=3)
    ax.fill_between(x, 0, y, alpha=.3)
    ax.set(xlim=(0, len(x) - 1), ylim=(0, None), xticks=x)
    

    enter image description here

    More information on seaborn styles can be found in the docs.

提交回复
热议问题