Skip to content

xlim() breaks default scale_x_datetime() #1348

@alshan

Description

@alshan
from datetime import datetime, timedelta, timezone
import numpy as np
import pandas as pd
from lets_plot import *

LetsPlot.setup_html()

def squiggle(x):
    return np.sin(3*x) / (x * (np.cos(x) + 2))


N=50
ys = [squiggle(x) for x in xs ]

# Berlin DST transition: March 30, 2025 at 2:00 AM
# Cover ±3 days: March 27 - April 2, 2025 (6 days total)

# Generate equally spaced UNIX timestamps (in seconds)
start_timestamp = datetime(2025, 3, 27, 0, 0, tzinfo=timezone.utc).timestamp()
end_timestamp = datetime(2025, 4, 2, 23, 59, tzinfo=timezone.utc).timestamp()
unix_timestamps = np.linspace(start_timestamp, end_timestamp, N)

# Convert to pandas datetime series with Berlin timezone
xs_datetime = pd.to_datetime(unix_timestamps, unit='s', utc=True).tz_convert('Europe/Berlin')

df = pd.DataFrame({
    'xs': xs_datetime,
    'ys': ys
})

p = ggplot(data = df, mapping=aes('xs', 'ys')) + geom_line()
p

Image

p + xlim(
    pd.Timestamp('2025-03-29 23:00:00', tz='Europe/Berlin'),
    pd.Timestamp('2025-03-30 08:00:00', tz='Europe/Berlin')
)

Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions