image
LP小透明

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

免责声明:网站内容仅供个人学习记录,禁做商业用途,转载请注明出处。

版权所有 © 2017-2020 NEUSNCP个人学习笔记 辽ICP备17017855号-2

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

LP小透明    2019年6月29日 12:10:35

使用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}

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
最近更新: 2020年3月27日 22:03:09
浏览: 16.1K

[[total]] 条评论

添加评论
  1. [[item.time]]
    [[item.user.username]] [[item.floor]]楼
  2. 点击加载更多……
  3. 添加评论