全息图(或 hvplot)中带有标记的线图
Lineplot with markers in holoviews (or hvplot)
我知道如何用 holoviews / hvplot 制作线图。
但是如何将数据点的标记添加到我的线图中?
情节应该是这样的:
下面是一些示例代码:
# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv
# create sample data
df = pd.DataFrame({
'date_col': pd.date_range(start='1-1-2020', freq='m', periods=12),
'value_col': np.random.normal(size=12),
})
您可以通过将线图与散点图组合来向线图添加标记。
在 Holoviews 中,这称为 overlay 并且可以使用 * 符号 .
完成此 叠加
Hvplot 解决方案:
# create a line plot
line_plot = df.hvplot.line(
x='date_col',
y='value_col',
)
# scatter plot with some extra styling options just for fun
scatter_plot = df.hvplot.scatter(
x='date_col',
y='value_col',
).opts(color='black', size=20, marker='o')
# overlay the scatterplot on the lineplot to get markers added to your lineplot
line_plot * scatter_plot
Holoviews 解决方案:
# overlay the scatter plot on the curve by using the * symbol
hv.Curve(df) * hv.Scatter(df).opts(color='black', size=20, marker='o')
我知道如何用 holoviews / hvplot 制作线图。
但是如何将数据点的标记添加到我的线图中?
情节应该是这样的:
下面是一些示例代码:
# import libraries
import numpy as np
import pandas as pd
import hvplot.pandas
import holoviews as hv
# create sample data
df = pd.DataFrame({
'date_col': pd.date_range(start='1-1-2020', freq='m', periods=12),
'value_col': np.random.normal(size=12),
})
您可以通过将线图与散点图组合来向线图添加标记。
在 Holoviews 中,这称为 overlay 并且可以使用 * 符号 .
Hvplot 解决方案:
# create a line plot
line_plot = df.hvplot.line(
x='date_col',
y='value_col',
)
# scatter plot with some extra styling options just for fun
scatter_plot = df.hvplot.scatter(
x='date_col',
y='value_col',
).opts(color='black', size=20, marker='o')
# overlay the scatterplot on the lineplot to get markers added to your lineplot
line_plot * scatter_plot
Holoviews 解决方案:
# overlay the scatter plot on the curve by using the * symbol
hv.Curve(df) * hv.Scatter(df).opts(color='black', size=20, marker='o')