ChartAxis
- class ChartAxis
A chart axis, accessed through
Chart.category_axisandChart.value_axisfor the primary axes, orChart.secondary_category_axisandChart.secondary_value_axisfor the secondary axes.Use
set()to change several attributes in one operation. On xlwings Lite, use the asynchronous getters to fetch the current values from Excel.>>> # Assumes an existing workbook object named book. >>> chart = book.sheets[0].charts[0] >>> chart.value_axis.set( ... title="Revenue", minimum_scale=0, major_unit=10_000 ... )
Added in version 0.37.5.
- property crosses: str
"automatic","minimum", or"maximum". On a category axis,"maximum"means the value axis crosses at the last category. Reads return"custom"if the crossing point was set to a specific value in Excel.- Type:
Returns or sets where the other axis crosses this axis
- async get_crosses()
Fetches where the other axis crosses this axis:
"automatic","minimum","maximum", or"custom".Requires xlwings Lite.
- Return type:
str
- async get_major_unit()
Fetches the resolved major-unit interval.
Requires xlwings Lite.
- Return type:
float
- async get_maximum_scale()
Fetches the resolved maximum scale.
Requires xlwings Lite.
- Return type:
float
- async get_minimum_scale()
Fetches the resolved minimum scale.
Requires xlwings Lite.
- Return type:
float
- async get_number_format()
Fetches the tick-label number format.
Requires xlwings Lite.
- Return type:
str
- async get_reverse_order()
Fetches whether the axis is plotted in reverse order.
Requires xlwings Lite.
- Return type:
bool
- async get_title()
Fetches the axis title. Returns
Noneif the axis or title is hidden.Requires xlwings Lite.
- Return type:
str | None
- property major_unit: float
Returns or sets the interval between major tick marks. Set to
Noneto restore Excel’s automatic interval; reads return the resolved value.- Setter type:
float | None
- property maximum_scale: float
Returns or sets the maximum scale. Set to
Noneto restore Excel’s automatic scale; reads return the resolved numeric value.- Setter type:
float | None
- property minimum_scale: float
Returns or sets the minimum scale. Set to
Noneto restore Excel’s automatic scale; reads return the resolved numeric value.- Setter type:
float | None
- property reverse_order: bool
Returns or sets whether the axis plots its categories or values in reverse order (“Categories in reverse order” / “Values in reverse order” in Excel).
Bar charts draw the first category at the bottom; reversing the category axis puts it at the top. This only flips the display order, it doesn’t sort: sort the source data to order the bars by value. Excel then also moves the value axis to the other side; set
crossesto"maximum"to keep it where it was:>>> chart.category_axis.set(reverse_order=True, crosses="maximum")
- set(*, title=..., minimum_scale=..., maximum_scale=..., major_unit=..., number_format=..., visible=..., reverse_order=..., crosses=...)
Sets one or more axis attributes in one operation.
Only supplied attributes are changed, and all arguments are validated before anything is written.
visible=Trueis applied before the other attributes;visible=Falseis applied last so it describes the final state.- Parameters:
title (str | None) – Axis title, or
Noneto hide it.minimum_scale (float | None) – Minimum scale, or
Nonefor automatic scaling.maximum_scale (float | None) – Maximum scale, or
Nonefor automatic scaling.major_unit (float | None) – Positive major-unit interval, or
Nonefor automatic.number_format (str) – Format code for the tick labels.
visible (bool) – Whether the axis is shown.
reverse_order (bool) – Whether the axis is plotted in reverse order.
crosses (str) – Where the other axis crosses this axis:
"automatic","minimum", or"maximum".