plotly-express-9-plotly绘制线型图Line
本文中介绍的是利用plotly
绘制线型图,使用的是line()
和go.Line()
方法
With
px.line
, each data point is represented as a vertex (which location is given by thex
andy
columns) of a polyline mark in 2D space.
导入库
1 | import pandas as pd |
使用px实现
在plotly_express
中是通过px.line
方法来实现的
Simple Line Plot with plotly.express
1 | data = px.data.gapminder() |
dash中实现
在dash中实现的一个通用方法
1 | fig = go.Figure() # or any Plotly Express function e.g. px.bar(...) |
Line Plot with column encoding color
1 | df = px.data.gapminder().query("continent=='Oceania'") |
使用go.Line实现
官网demo
1 | np.random.seed(1) |
Style Line Plots
如何给线性图设置风格
1 | # Add data |
1 | aliceblue, antiquewhite, aqua, aquamarine, azure, |
Connect Data Gaps
如果数据中存在缺失值或者说断点,如何处理?
1 | x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] |
Label Lines with Annotations
如何给图中的某些点添加注释annotions
1 | fig = go.Figure() |
Filled Lines
通过一个例子学习如何画出带有填充区域的线型图
1 | x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |