Specify Date Axis Tick Formats#

Charts with axis_type="date" can have ticks be formatted to match certain styles especially for dates. Use the tick_format and pass a python date format string (Python Docs).

Use the tick_angle argument to control the direction of the tick. Values are represented as an integer number of degrees (-360, 360). Negative values are a counter-clockwise rotation.

  • For example, the x-axis is a date type and with a tick_format=="%b %d", will show ticks with only the month and day. The tick angle is set to 0 to not have any rotation.

  • By default, date ticks are formatted as mm/dd/yyyy or (%m/%d/%y in python).

  • By default, tick angles are rotated as -45 degrees.

/home/runner/work/visualization_toolkit/visualization_toolkit/visualization_toolkit/helpers/plotly/charts/core/chart.py:651: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy



import pandas as pd
from datetime import date
from dateutil.relativedelta import relativedelta

from visualization_toolkit.helpers.plotly import chart, axis, series


fig = chart(
    pdf,
    x_axis=axis(
        column_name="day",
        axis_type="date",
        label="Week Ending",
        tick_interval=relativedelta(days=14),
        tick_format="%b %d",
        tick_angle=0,
        axis_min=date(2024, 6, 30),
        axis_max=date(2024, 10, 20),
    ),
    chart_series=[
        series(
            column_name="abnb_gbv_share",
            label="ABNB GBV Share",
            color="dark-blue",
        ),
    ],
    y1_axis=axis(
        axis_type="percent",
        axis_min=0,
        axis_max=1,
        tick_format="0.0%",
    ),
)

fig

Total running time of the script: (0 minutes 0.019 seconds)

Gallery generated by Sphinx-Gallery