{"id":532,"date":"2026-04-04T11:32:04","date_gmt":"2026-04-04T03:32:04","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=532"},"modified":"2026-03-23T07:43:03","modified_gmt":"2026-03-23T07:43:03","slug":"how-to-set-multiple-axes-chart-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-multiple-axes-chart-using-xlwings\/","title":{"rendered":"How To Set Multiple Axes Chart Using xlwings?"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>&#8211; Bind a series to the primary or secondary axis\u00a0<\/p>\n<p>The **AxisGroup** property of the **Series** object is used to assign a series to either the primary axis (when the value is 1) or the secondary axis (when the value is 2).<\/p>\n<p>&#8211; Set up the axes\u00a0<\/p>\n<p>You can access the **Axis** object through the **Chart** object with the following syntax:<\/p>\n<p>axs=cht.Axes(Type,AxisGroup)<\/p>\n<p>Where `cht` is the **Chart** object. The **Type** parameter indicates the type of axis. A value of 1 means a category axis, while 2 means a value axis. The **AxisGroup** parameter specifies whether the axis is primary (1) or secondary (2). By default, the primary axis is displayed on the left, and the secondary axis is displayed on the right. This allows the creation of a dual-axis chart, where two charts are overlaid using the same horizontal axis and different vertical axes.<\/p>\n<p>sht.api.Range(&#8216;A1:B7&#8217;).Select()\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\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 20,20,350,200,True).Chart<\/p>\n<p>cht.SeriesCollection(1).AxisGroup=1\u00a0\u00a0\u00a0 #Y axis for series 1<\/p>\n<p>cht.SeriesCollection(2).AxisGroup=2\u00a0\u00a0\u00a0 #Y axis for series 2<\/p>\n<p>cht.SeriesCollection(2).ChartType=xw.constants.ChartType.xlLine<\/p>\n<p>cht.SeriesCollection(2).MarkerStyle=xw.constants.MarkerStyle.xlMarkerStyleTriangle<\/p>\n<p>cht.SeriesCollection(2).MarkerForegroundColor=xw.utils.rgb_to_int((0,0,255))<\/p>\n<p>cht.SeriesCollection(2).MarkerSize=8<\/p>\n<p>cht.SeriesCollection(2).HasDataLabels=True<\/p>\n<p>cht.SeriesCollection(1).HasDataLabels=True<\/p>\n<p>\u00a0<\/p>\n<p>axs1=cht.Axes(2,1)<\/p>\n<p>axs1.MinimumScale=0<\/p>\n<p>axs1.MaximumScale=60<\/p>\n<p>axs1.HasTitle=True<\/p>\n<p>axs1.AxisTitle.Text=&#8217;Y Axis 1&#8242;<\/p>\n<p>\u00a0<\/p>\n<p>axs2=cht.Axes(2,2)<\/p>\n<p>axs2.MinimumScale=10<\/p>\n<p>axs2.MaximumScale=160<\/p>\n<p>axs2.HasTitle=True<\/p>\n<p>axs2.AxisTitle.Text=&#8217;Y Axis 2&#8242;<\/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-6.jpg\" alt=\"\" class=\"wp-image-1168\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-6.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-6-300x262.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-01-6-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 - Multi-axis chart\n\nimport xlwings as xw\nimport os\n\nroot=os.getcwd()\napp=xw.App(visible=True,add_book=False)\nwb=app.books.open('multiaxis.xlsx',read_only=False)\nsht=wb.sheets('Sheet1')\n\nsht.api.Range('A1:B7').Select()    #Data\ncht=sht.api.Shapes.AddChart2(-1,xw.constants.ChartType.xlColumnClustered,\\\n                        20,20,350,200,True).Chart\ncht.SeriesCollection(1).AxisGroup=1    #Y axis for series 1\ncht.SeriesCollection(2).AxisGroup=2    #Y axis for series 2\ncht.SeriesCollection(2).ChartType=xw.constants.ChartType.xlLine\ncht.SeriesCollection(2).MarkerStyle=xw.constants.MarkerStyle.xlMarkerStyleTriangle\ncht.SeriesCollection(2).MarkerForegroundColor=xw.utils.rgb_to_int((0,0,255))\ncht.SeriesCollection(2).MarkerSize=8\ncht.SeriesCollection(2).HasDataLabels=True\ncht.SeriesCollection(1).HasDataLabels=True\n\naxs1=cht.Axes(2,1)\naxs1.MinimumScale=0\naxs1.MaximumScale=60\naxs1.HasTitle=True\naxs1.AxisTitle.Text='Y Axis 1'\n\naxs2=cht.Axes(2,2)\naxs2.MinimumScale=10\naxs2.MaximumScale=160\naxs2.HasTitle=True\naxs2.AxisTitle.Text='Y Axis 2'\n  \ncht.ChartTitle.Caption='Multi-axis Plot'\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-20.jpg\" alt=\"\" class=\"wp-image-1170\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-20.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-20-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-20-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-532","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/532","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=532"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"predecessor-version":[{"id":1171,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/532\/revisions\/1171"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}