image
LP小透明

当你感到无聊的时候,就去学习,因为一旦你开始认真学习,就会立刻发现比学习有趣的事来打断你的学习

Python-matplotlib.pyplot 绘图设置背景色(主题)

LP小透明    2019-06-29 12:10

使用VScode+Jupyter绘图时,如果默认的主题是dark的,绘制出来的图也是深色背景的。如果想要好看一点的样式,就需要设置plt的样式了。
def draw(data):    
    x = range(len(data))
    y = [data[d] for d in data]
    z = zip(x, y)
    
    styles = plt.style.available
    print(styles)

    for s in styles:
        plt.suptitle('Style: %s'%s, fontsize=16, fontweight='bold')
        plt.style.use(s) # 设置使用的样式
        plt.plot(x, y, color='#3498DB', linewidth=1, alpha=0.9)
        plt.xlim(1, len(data))  # 限定X轴范围
        ax = plt.axes()
        plt.xlabel('Day')
        plt.ylabel('Connections Num')
        plt.show()

data的数据格式:
{0: 19, 1: 15, 2: 32, 3: 23, 4: 28}

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Last Modified: 2020-03-27 22:03
Views: 15.3K

[[total]] comments

Post your comment
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]Floor
  2. Click to load more...
  3. Post your comment