{"id":618,"date":"2026-05-17T11:15:23","date_gmt":"2026-05-17T03:15:23","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=618"},"modified":"2026-03-24T06:38:57","modified_gmt":"2026-03-24T06:38:57","slug":"how-to-create-new-chart-combine-existing-charts-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-create-new-chart-combine-existing-charts-using-xlwings\/","title":{"rendered":"How To Create New Chart: Combine Existing Charts Using xlwings?"},"content":{"rendered":"<p style=\"margin: 0in; font-size: 16.0pt;\"><span lang=\"zh-CN\" style=\"font-family: 'Microsoft YaHei';\">\u3010<\/span><span lang=\"en-US\" style=\"font-weight: bold; font-family: Calibri;\">Example<\/span><span lang=\"zh-CN\" style=\"font-family: 'Microsoft YaHei';\">\u3011<\/span><\/p>\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\/05\/3-20.jpg\" alt=\"\" class=\"wp-image-1497\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/05\/3-20.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/05\/3-20-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/05\/3-20-768x660.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>import xlwings as xw\nimport numpy as np\nimport os\n\ndef set_style(cht):\n    cht.ChartArea.Format.Line.Visible=False\n    cht.PlotArea.Format.Fill.Visible = False\n    cht.PlotArea.Format.Line.Visible = True\n    cht.PlotArea.Format.Line.ForeColor.RGB=xw.utils.rgb_to_int((200,200,200))\n    #cht.PlotArea.Format.Line.ForeColor.ObjectThemeColor = msoThemeColorText1\n    ax1 = cht.Axes(1)\n    ax2 = cht.Axes(2)\n    ax1.HasTitle = True\n    ax1.AxisTitle.Text = 'Categories'\n    ax1.AxisTitle.Font.Size = 10\n    ax1.TickLabels.Font.Size = 8\n    #ax1.TickLabels.NumberFormat = '0.00'\n    ax1.HasMajorGridlines = False\n    ax2.HasTitle = True\n    ax2.AxisTitle.Text = 'Values'\n    ax2.AxisTitle.Font.Size = 10\n    ax2.TickLabels.Font.Size = 8\n    ax2.HasMajorGridlines = False\n    cht.HasTitle = True\n    #cht.ChartTitle.Caption = 'Plot'\n    #cht.ChartTitle.Font.Size = 12\n\ndef draw_rnd_scatter(cht,x,y,n,w):\n    cht.SeriesCollection().NewSeries()\n    count=cht.SeriesCollection().Count\n    rd=&#91;]\n    for i in range(n):\n        rd.append(x-w\/2+w*np.random.rand(1)&#91;0])\n    cht.SeriesCollection(count).ChartType=-4169\n    cht.SeriesCollection(count).XValues=rd\n    cht.SeriesCollection(count).Values=y\n\nroot=os.getcwd()\napp=xw.App(visible=True,add_book=False)\nwb=app.books.open(root+r'\/data.xlsx',read_only=False)\nsht=wb.sheets('Sheet1')\n\nshp=sht.api.Shapes.AddChart2()\nshp.Left=20\ncht=shp.Chart\ncht.ChartType=xw.constants.ChartType.xlXYScatter\nax1=cht.Axes(1)\nax2=cht.Axes(2)\nax1.MinimumScale=0.5\nax1.MaximumScale=4.5\nax2.MinimumScale=0\nax2.MaximumScale=0.35\n\nset_style(cht)\n\ndata=sht.range('B2:E21').value\ndt=np.transpose(data)\ndt1=dt&#91;0]\ndt2=dt&#91;1]\ndt3=dt&#91;2]\ndt4=dt&#91;3]\naveg=&#91;0 for _ in range(4)]\naveg&#91;0]=app.api.WorksheetFunction.Average(dt1)\naveg&#91;1]=app.api.WorksheetFunction.Average(dt2)\naveg&#91;2]=app.api.WorksheetFunction.Average(dt3)\naveg&#91;3]=app.api.WorksheetFunction.Average(dt4)\n\ncht.SeriesCollection().NewSeries()\nn=cht.SeriesCollection().Count\ncht.SeriesCollection(n).ChartType=xw.constants.ChartType.xlColumnClustered\ncht.SeriesCollection(n).XValues=&#91;1,2,3,4]\ncht.SeriesCollection(n).Values=aveg\ncht.SeriesCollection(n).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((76,200,132))\ncht.ChartGroups(1).GapWidth=100\n  \ndraw_rnd_scatter(cht,1,dt1,20,0.5)\ndraw_rnd_scatter(cht, 2, dt2, 20, 0.5)\ndraw_rnd_scatter(cht, 3, dt3, 20, 0.5)\ndraw_rnd_scatter(cht, 4, dt4, 20, 0.5)\n\n#wb.save()\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\/05\/3-21.jpg\" alt=\"\" class=\"wp-image-1498\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/05\/3-21.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/05\/3-21-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/05\/3-21-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":[24],"tags":[],"class_list":["post-618","post","type-post","status-publish","format-standard","hentry","category-xlwings-advanced-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/618","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=618"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/618\/revisions"}],"predecessor-version":[{"id":1499,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/618\/revisions\/1499"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=618"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=618"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=618"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}