{"id":529,"date":"2026-04-02T17:25:22","date_gmt":"2026-04-02T09:25:22","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=529"},"modified":"2026-03-23T07:17:27","modified_gmt":"2026-03-23T07:17:27","slug":"how-to-set-tick-marks-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-tick-marks-using-xlwings\/","title":{"rendered":"How To Set Tick Marks Using xlwings?"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>Tick marks are short lines on the axis used to help determine the position of data points on the chart. There are major and minor tick marks. Use the **MajorTickMark** and **MinorTickMark** properties of the **Axis** object to set the major and minor tick marks.\u00a0<\/p>\n<p>The possible values for **MajorTickMark** and **MinorTickMark** are as follows:<\/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>xlTickMarkCross<\/p>\n<\/td>\n<td>\n<p>4<\/p>\n<\/td>\n<td>\n<p>Across the axis<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickMarkInside<\/p>\n<\/td>\n<td>\n<p>2<\/p>\n<\/td>\n<td>\n<p>Inside the axis<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickMarkNone<\/p>\n<\/td>\n<td>\n<p>-4142<\/p>\n<\/td>\n<td>\n<p>No marker<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>xlTickMarkOutside<\/p>\n<\/td>\n<td>\n<p>3<\/p>\n<\/td>\n<td>\n<p>Outside the axis<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Use the **TickMarkSpacing** property to return or set the spacing of major tick marks, indicating how often a major tick mark is displayed for every set of data points. This is only applicable for category axes and series axes and can be a value between 1 and 31999.<\/p>\n<p>Use the **MajorUnit** and **MinorUnit** properties to set the units for the major and minor tick marks on the value axis.<\/p>\n<p>Set **MajorUnitIsAuto** and **MinorUnitIsAuto** properties to `True` to have Excel automatically calculate the major and minor tick units for the value axis.<\/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>axs.MajorTickMark = 4<\/p>\n<p>axs.MinorTickMark = 2<\/p>\n<p>axs.TickMarkSpacing = 1<\/p>\n<p>axs2.MajorUnit = 40<\/p>\n<p>axs2.MinorUnit = 10<\/p>\n<p>axs2.MajorUnitIsAuto=True<\/p>\n<p>axs2.MinorUnitIsAuto=True<\/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-3.jpg\" alt=\"\" class=\"wp-image-1157\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-3.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-3-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-3-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 - Major tick marks\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\naxs.MajorTickMark = 4\naxs.MinorTickMark = 2\naxs.TickMarkSpacing = 1\naxs2.MinorTickMark = 2\naxs2.MajorUnit = 40\naxs2.MinorUnit = 10\n#axs2.MajorUnitIsAuto=True\n#axs2.MinorUnitIsAuto=True\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-17.jpg\" alt=\"\" class=\"wp-image-1158\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-17.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-17-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-17-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-529","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/529","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=529"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"predecessor-version":[{"id":1159,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/529\/revisions\/1159"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}