Suppose i have the data frame below:
I checked the documentation but it's only based on a single column.
Reproducible code:
x = np.random.normal(100,5,100)
data = pd.DataFrame(x)
epsilon = 10
data.columns = ['x']
data['lower'] = x - epsilon
data['upper'] = x + epsilon
data
I'd actually like to use altair, since i like it's interactivity.
You can use forecast function under Analytics pane to set confidence interval: However, t he forecasting feature is only available for line chart visuals so that you could not show shaded areas in chart line instead of using Area chart. If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
The most significant thing about creating visualizations in Altair is that you can disengage the style of the graph, whether line or scatter or bar (called the mark) from the undisputable encoding of the data that can be Categorical (Nominal or Ordered) or Quantitative or Temporal and so on….
The transform_filters function of Altair, reduces the dataframe to the selection of stock and “nearest” Date on x-axis chosen. The output is the graph seen at the top of the article where only the stock selected is charted with color and the tooltip shows its price, whereas the rest and sent to the background in grey.
You can layer a line and an area chart, usng the y
and y2
encodings to specify the range:
import altair as alt
import pandas as pd
import numpy as np
x = np.random.normal(100,5,100)
epsilon = 10
data = pd.DataFrame({
'x': x,
'lower': x - epsilon,
'upper': x + epsilon
}).reset_index()
line = alt.Chart(data).mark_line().encode(
x='index',
y='x'
)
band = alt.Chart(data).mark_area(
opacity=0.5
).encode(
x='index',
y='lower',
y2='upper'
)
band + line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With