【Method】
The **ScaleType** property of the **Axis** object returns or sets the scale type for the value axis, as shown in the table below. When the **ScaleType** property is set to `xw.constants.ScaleType.xlScaleLogarithmic`, the axis uses a logarithmic scale, allowing you to create a logarithmic scale chart.
|
Name |
Value |
Description |
|
xlScaleLinear |
-4132 |
Linear scale |
|
xlScaleLogarithmic |
-4133 |
Logarithmic scale |
sht.api.Range(‘A1:B7’).Select()
cht=sht.api.Shapes.AddChart().Chart
cht.Axes(2).ScaleType=xw.constants.ScaleType.xlScaleLogarithmic #Logarithmic scale
cht.Axes(2).HasMinorGridlines=True
【Example】

【Code】
#Coordinate system - Logarithmic scale chart
import xlwings as xw
import os
root = os.getcwd()
app = xw.App(visible=True, add_book=False)
wb=app.books.open(root+r'/P1P2.xlsx',read_only=False)
sht=wb.sheets(1)
sht.api.Range('A1:B7').Select()
cht=sht.api.Shapes.AddChart().Chart
cht.Axes(2).ScaleType=xw.constants.ScaleType.xlScaleLogarithmic #Logarithmic scale
cht.Axes(2).HasMinorGridlines=True
#wb.save()
#wb.close()
#app.kill()

Leave a Reply