{"id":530,"date":"2026-04-03T11:57:51","date_gmt":"2026-04-03T03:57:51","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=530"},"modified":"2026-03-23T07:20:48","modified_gmt":"2026-03-23T07:20:48","slug":"how-to-set-tick-labels-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-tick-labels-using-xlwings\/","title":{"rendered":"How To Set Tick Labels Using xlwings?"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>The text labels corresponding to the positions of the major tick marks on the axis are called **tick labels**. These labels annotate the values or categories corresponding to the major tick marks.<\/p>\n<p>For a category axis, the text of the tick labels represents the names of the associated categories in the chart. By default, the tick labels for a category axis are numbers, which start from 1 and increase in order from left to right. The **TickLabelSpacing** property can be used to set how many categories are displayed before a tick label is shown.<\/p>\n<p>For a value axis, the text labels correspond to the major unit, minimum scale, and maximum scale properties of the axis. To change the tick label text for a value axis, you need to modify the values of these properties.<\/p>\n<p>The **TickLabels** property of the **Axis** object returns a **TickLabels** object that represents the tick labels on the axis. By using the properties and methods of the **TickLabels** object, you can set various properties of the tick labels, such as font, number format, display direction, offset, and alignment.<\/p>\n<p>Use the **TickLabelPosition** property to specify the position of the tick labels on the axis. The values for this property are constants or values as listed in the table below:<\/p>\n<table>\n<tbody>\n<tr>\n<td>\n<p>Name<\/p>\n<\/td>\n<td>\n<p>Value<\/p>\n<\/td>\n<td>\n<p>Description<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickLabelPositionHigh<\/p>\n<\/td>\n<td>\n<p>-4127<\/p>\n<\/td>\n<td>\n<p>Top or right side of the chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickLabelPositionLow<\/p>\n<\/td>\n<td>\n<p>-4134<\/p>\n<\/td>\n<td>\n<p>Bottom or left side of the chart<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickLabelPositionNextToAxis<\/p>\n<\/td>\n<td>\n<p>4<\/p>\n<\/td>\n<td>\n<p>Next to the axis (where the axis is not at any side of the chart)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickLabelPositionNone<\/p>\n<\/td>\n<td>\n<p>-4142<\/p>\n<\/td>\n<td>\n<p>No tick labels<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The **TickLabelSpacing** property allows you to return or set the number of categories or data series between each tick label. This property is only applicable for category axes and series axes and can be set to a value between 1 and 31999.<\/p>\n<p>When the **TickLabelSpacingIsAuto** property is set to `True`, Excel will automatically adjust the spacing of the tick labels.<\/p>\n<p>sht.api.Range(&#8216;A1:B7&#8217;).Select()\u00a0\u00a0\u00a0 #Data<\/p>\n<p>cht=sht.api.Shapes.AddChart().Chart\u00a0\u00a0\u00a0 #Add chart<\/p>\n<p>axs=cht.Axes(1)\u00a0\u00a0\u00a0 #Horizontal axis<\/p>\n<p>axs2=cht.Axes(2)\u00a0\u00a0\u00a0 #Vertical axis<\/p>\n<p>tl=axs2.TickLabels\u00a0\u00a0\u00a0 #Vertical axis tick labels<\/p>\n<p>tl.NumberFormat = &#8216;0.00&#8217;\u00a0\u00a0\u00a0 #Number format<\/p>\n<p>axs2.TickLabelPosition=xw.constants.Constants.xlHigh<\/p>\n<p>\u00a0<\/p>\n<p>\u3010<b>Example<\/b>\u3011<\/p>\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"768\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-4.jpg\" alt=\"\" class=\"wp-image-1160\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-4.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-4-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-4-768x670.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p>\u3010<strong>Code<\/strong>\u3011<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Axis - Tick labels\n\nimport xlwings as xw\nimport os\n\nroot = os.getcwd()\napp = xw.App(visible=True, add_book=False)\nwb=app.books.open(root+r'\/P1P2.xlsx',read_only=False)\nsht=wb.sheets(1)\n\nsht.api.Range('A1:B7').Select()    #Data\ncht=sht.api.Shapes.AddChart().Chart    #Add chart\naxs=cht.Axes(1)    #Horizontal axis\naxs2=cht.Axes(2)    #Vertical axis\ntl=axs2.TickLabels    #Vertical axis tick labels\ntl.NumberFormat = '0.00'    #Number format\n\naxs2.TickLabelPosition=xw.constants.Constants.xlHigh\n\n#wb.save()\n#wb.close()\n#app.kill()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"880\" height=\"756\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-18.jpg\" alt=\"\" class=\"wp-image-1162\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-18.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-18-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-18-768x660.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Method<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-530","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/comments?post=530"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/530\/revisions"}],"predecessor-version":[{"id":1163,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/530\/revisions\/1163"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}