79298741

Date: 2024-12-21 01:39:51
Score: 0.5
Natty:
Report link

You're just missing the clip parameter in the Chart.mark_area method. From the Altair docs, this parameter determines "Whether a mark be clipped to the enclosing group's width and height".

So, all you need to do is add the following line (don't forget a comma at the end of the line above!):

alt.Chart(price_data).mark_area(
    line={'color': 'darkgreen'},
    color=alt.Gradient(
        gradient='linear',
        stops=[alt.GradientStop(color='white', offset=0),
               alt.GradientStop(color='darkgreen', offset=1)],
        x1=1,
        x2=1,
        y1=1,
        y2=0
    ),
    clip=True, # add this line
).encode(
    alt.X('date:T', title="Date"),
    alt.Y('close:Q', scale=alt.Scale(domain=[y_min, y_max]), title="Close Price")
).properties(
    title=f"{symbol} Price Trend"
)

Chart differences

For the dataset I had, here is the before chart:

Before chart

And the after chart:

Chart with clip=True applied

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: dnelson17