{"id":16,"date":"2026-04-01T18:27:40","date_gmt":"2026-04-01T10:27:40","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=16"},"modified":"2026-03-23T07:10:33","modified_gmt":"2026-03-23T07:10:33","slug":"how-to-set-axis-title-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-axis-title-using-xlwings\/","title":{"rendered":"How To Set Axis Title Using xlwings?"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>Use the **HasTitle** property of the **Axis** object to set whether the axis title is displayed, and the **AxisTitle** property to set the text content of the axis title. Note that the **HasTitle** property must be set to `True` before the **AxisTitle** property can be set. The **AxisTitle** property returns an **AxisTitle** object, which you can use to set the title text and font for the 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.HasTitle=True\u00a0\u00a0\u00a0 #Horizontal axis has title<\/p>\n<p>axs.AxisTitle.Caption=&#8217;X Axis Title&#8217;\u00a0\u00a0\u00a0 #Title text<\/p>\n<p>axs.AxisTitle.Font.Italic=True\u00a0\u00a0\u00a0 #Italic font<\/p>\n<p>axs.AxisTitle.Font.Color=xw.utils.rgb_to_int((255,0,0))\u00a0\u00a0\u00a0 #Red<\/p>\n<p>axs2.HasTitle=True\u00a0\u00a0\u00a0 #Vertical axis has title<\/p>\n<p>axs2.AxisTitle.Caption=&#8217;Y Axis Title&#8217;\u00a0\u00a0\u00a0 #Title text<\/p>\n<p>axs2.AxisTitle.Font.Bold=True\u00a0\u00a0\u00a0 #Bold font<\/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-1.jpg\" alt=\"\" class=\"wp-image-1148\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-1.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-1-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-1-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 Titles\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.HasTitle=True    #Horizontal axis has title\naxs.AxisTitle.Caption='X Axis Title'    #Title text\naxs.AxisTitle.Font.Italic=True    #Italic font\naxs.AxisTitle.Font.Color=xw.utils.rgb_to_int((255,0,0))    #Red\naxs2.HasTitle=True    #Vertical axis has title\naxs2.AxisTitle.Caption='Y Axis Title'    #Title text\naxs2.AxisTitle.Font.Bold=True    #Bold font\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-15.jpg\" alt=\"\" class=\"wp-image-1150\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-15.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-15-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-15-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-16","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/16","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=16"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions\/1151"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}