{"id":526,"date":"2026-03-31T18:38:04","date_gmt":"2026-03-31T10:38:04","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=526"},"modified":"2026-03-23T07:04:24","modified_gmt":"2026-03-23T07:04:24","slug":"how-to-set-axes-object-and-axis-object-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-axes-object-and-axis-object-using-xlwings\/","title":{"rendered":"How To Set Axes Object and Axis Object Using xlwings?"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>In Excel, the **Axis** object represents a single axis, and its plural form, the **Axes** object, represents multiple axes and the coordinate system they form. For a 2D coordinate system, there are horizontal and vertical axes; for a 3D coordinate system, there are axes in three directions.<\/p>\n<p>To access the **Axis** object using the API, the syntax is as follows:<\/p>\n<p>axs=cht.Axes(Type,AxisGroup)<\/p>\n<p>Where `cht` is the **Chart** object, and the two parameters are:<\/p>\n<p>&#8211; **Type** &#8211; A required parameter, with values 1, 2, or 3. When `Type = 1`, the axis displays categories (usually for the horizontal axis in a chart); when `Type = 2`, the axis displays values (usually for the vertical axis); when `Type = 3`, the axis displays data series (only used for 3D charts).<\/p>\n<p>&#8211; **AxisGroup** &#8211; An optional parameter that specifies whether the axis is primary or secondary. If set to 2, it means the axis is a secondary axis. If set to 1, it means the axis is a primary axis.<\/p>\n<p>You can use the **Chart** object&#8217;s **Axes** property to get the horizontal and vertical axes and set their properties. The **Border** property can be used to modify the axis&#8217;s color, line style, width, etc.<\/p>\n<p>sht.api.Range(&#8216;A1:B7&#8217;).Select()\u00a0\u00a0\u00a0\u00a0\u00a0 #Data<\/p>\n<p>cht=sht.api.Shapes.AddChart2(-1,xw.constants.ChartType.xlColumnClustered,\\<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 200,20,300,200,True).Chart\u00a0\u00a0\u00a0\u00a0\u00a0 #Add chart<\/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\/03\/2-01-5.jpg\" alt=\"\" class=\"wp-image-1141\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-5.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-5-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-01-5-768x670.jpg 768w\" sizes=\"auto, (max-width: 880px) 100vw, 880px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u3010<strong>Code<\/strong>\u3011<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Coordinate system - Create chart\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.AddChart2(-1,xw.constants.ChartType.xlColumnClustered,\\\n                 200,20,300,200,True).Chart      #Add chart\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\/03\/2-13.jpg\" alt=\"\" class=\"wp-image-1142\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-13.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-13-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/03\/2-13-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-526","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/526","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=526"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":1143,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/526\/revisions\/1143"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}