以柱状图为例,看看Plotly多种内置样式(template)

目录

一、查看Plotly所有内置样式

二、数据准备

三、逐个样式测试

3.1 'ggplot2'

 3.2 'seaborn'

 3.3 'simple_white'

 3.4 'plotly'

 3.5 'plotly_white'

 3.6 'plotly_dark'

 3.7 'presentation'

 3.8 'xgridoff'

 3.9 'ygridoff'

 3.10 'gridon'

 3.11 'none'

 四、总结

一、查看Plotly所有内置样式

import plotly.io as pio
pio.templates # 查看可选风格 默认风格是plotly
# 输出内容如下:
Templates configuration
-----------------------
    Default template: 'plotly'
    Available templates:
        ['ggplot2', 'seaborn', 'simple_white', 'plotly',
         'plotly_white', 'plotly_dark', 'presentation', 'xgridoff',
         'ygridoff', 'gridon', 'none']

这里能看到一共是11中样式,默认样式为'plotly' 

二、数据准备

这里自定义一个学生成绩表:

#定义一个Dataframe
import pandas as pd
data = pd.DataFrame({"姓名":["小明","小杨","小李","小宋","小赵","小孙","小杜","小马","小朱","小吴"],
                     "成绩":[65,94,67,78,85,24,36,99,89,45]})

 

三、逐个样式测试

3.1 'ggplot2'

import plotly.express as px
fig = px.bar(
    data, # 数据集
    x='姓名', # x轴
    y='成绩', # y轴
    color = '成绩',
    text = '成绩'
)
# 更改绘图样式
fig.update_layout(template = "ggplot2") # 选择其他样式,只需更改这里
fig.show()

 3.2 'seaborn'

 3.3 'simple_white'

 3.4 'plotly'

 3.5 'plotly_white'

 3.6 'plotly_dark'

 3.7 'presentation'

 3.8 'xgridoff'

 3.9 'ygridoff'

 3.10 'gridon'

 3.11 'none'

 四、总结

除了比较经典的‘ggplot2’,'seaborn'样式以外,个人比较推荐的是‘simple-white’这种干净整洁的样式,‘plotly-dark’是一个黑色背景的样式,感觉配上高亮的绘图颜色也会显示的很高级,如果需要做展示演讲,'presentation’也是很好的选择,字体更大,更清晰。大家可以根据演示效果,自己尝试

  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
长很长很长很长很长很长很长很长很长很长很长很长很长很长很长要在PyCharm中绘制动态柱状图,可以使用Plotly库。Plotly是一个交互式可视很长很长很长很长很长很长很长很长很长很长很长很长很长很长很化工具,可以用Python编程语言进行绘图。 下面是一个简单的示例代码,用于绘长很长很长很长很长很长很长很长很长很长很长很长很长很长很长制一个动态柱状图: ```python import plotly.graph_objs as go import plotly.offline as pyo import random from time import sleep data = [0] * 10 fig = go.Figure( data=[go.Bar(x=list很长很长很长很长很长很长很长很长很长很长很长很长很长很长很(range(10)), y=data)], layout_title_text='动态柱状图' ) pyo.plot(fig, filename='dynamic_bar_chart.html', auto_open=False) while True: data = data[1:] + [random.randint(1, 10)] fig.data长很长很长很长很长很长很长很长很长很长很长很长很长很长很长[0].y = data pyo.plot(fig, filename='dynamic_bar_chart.html', auto_open=False) sleep(1) 很长很长很长很长很长很长很长很长很长很长很长很长很长很长很``` 这段代码会生成一个初始值全为零的长度为10的列表。然后创建一个`Figure`对象,其中包含一个`Bar`图表对象,将初始列表作为Y轴数据。接下来,使用`plot`函数长很长很长很长很长很长很长很长很长很长很长很长很长很长很长将图表保存到本地文件`dynamic_bar_chart.html`中。 在无限循环中,每隔1秒钟更新很长很长很长很长很长很长很长很长很长很长很长很长很长很长很一次数据,将数据作为Y轴数据,并使用`plot`函数重新绘制图表。最终,你将获得一个动态柱状图,其高度随机变化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Terry_trans

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值