{"id":540,"date":"2026-04-08T11:02:19","date_gmt":"2026-04-08T03:02:19","guid":{"rendered":"https:\/\/xlwings.net\/blog\/?p=540"},"modified":"2026-03-23T09:20:38","modified_gmt":"2026-03-23T09:20:38","slug":"how-to-set-plot-area-2-using-xlwings","status":"publish","type":"post","link":"https:\/\/xlwings.net\/blog\/how-to-set-plot-area-2-using-xlwings\/","title":{"rendered":"How To Set Plot Area Using xlwings? 2"},"content":{"rendered":"<p>\u3010<b>Method<\/b>\u3011<\/p>\n<p>The chart area is the rectangular area that contains the entire chart, while the plot area is the rectangular area defined by the two axes. In Excel, the chart area is represented by the `ChartArea` object, and the plot area is represented by the `PlotArea` object. You can access these areas using the `ChartArea` and `PlotArea` properties of the `Chart` object.<\/p>\n<p>By continuously referencing the `ChartArea` and `PlotArea` objects&#8217; `Format.Fill` property, you can set the fill properties of both areas, such as their color, transparency, gradient fills, pattern fills, picture fills, texture fills, etc.<\/p>\n<p>Using the `Format.Shadow` property of the `ChartArea` and `PlotArea` objects, you can set additional shadow properties for these areas. The `Format.Shadow` property returns a `ShadowFormat` object with the following main properties:<\/p>\n<p>&#8211; **Visible**: Determines whether the shadow is visible.<\/p>\n<p>&#8211; **Blur**: Gets or sets the blur radius of the shadow.<\/p>\n<p>&#8211; **Transparency**: Gets or sets the transparency of the shadow (from 0.0 for opaque to 1.0 for fully transparent).<\/p>\n<p>&#8211; **OffsetX**: Gets or sets the horizontal offset of the shadow in points. Positive values shift the shadow to the right, while negative values shift it to the left.<\/p>\n<p>&#8211; **OffsetY**: Gets or sets the vertical offset of the shadow in points. Positive values shift the shadow downward, while negative values shift it upward.<\/p>\n<p>sht.api.Range(&#8216;A1:B7&#8217;).Select()<\/p>\n<p>cht=sht.api.Shapes.AddChart().Chart<\/p>\n<p>cha=cht.ChartArea\u00a0\u00a0\u00a0 #Chart Area<\/p>\n<p>cha.Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((155,255,0))<\/p>\n<p>cha.Shadow=True\u00a0\u00a0\u00a0 #Plot area shows shadow<\/p>\n<p>pla=cht.PlotArea\u00a0\u00a0\u00a0 #Plot area<\/p>\n<p>pla.Format.Fill.UserPicture(root+r&#8217;\/picpy2.jpg&#8217;)\u00a0\u00a0\u00a0 #Picture fill<\/p>\n<p>cht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))<\/p>\n<p>cht.Axes(2).HasMajorGridlines=False<\/p>\n<p>cha.Shadow=False<\/p>\n<p>pla.Format.Shadow.Visible=True\u00a0\u00a0\u00a0 #Plot area shows shadow<\/p>\n<p>pla.Format.Shadow.OffsetX=3\u00a0\u00a0\u00a0 #Horizontal offset of the shadow<\/p>\n<p>pla.Format.Shadow.OffsetY=3\u00a0\u00a0\u00a0 #Vertical offset of the shadow<\/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=\"756\" src=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-07-2.jpg\" alt=\"\" class=\"wp-image-1196\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-07-2.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-07-2-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-07-2-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 os\n\ndef set_style(cht):\n    cht.ChartArea.Format.Line.Visible=False\n    cht.PlotArea.Format.Fill.Visible=True\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\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\nsht.api.Range('A1:B7').Select()    #\ncht=sht.api.Shapes.AddChart2(-1, \\\n          xw.constants.ChartType.xlColumnClustered,20,20,350,250,True).Chart\ncht.SeriesCollection(1).Format.Fill.ForeColor.RGB=xw.utils.rgb_to_int((255,255,0))\ncht.PlotArea.Format.Fill.UserPicture('d:\/picpy2.jpg')\n\nset_style(cht)\n\ncht.Export(root+'\/cht.jpg')\ncht.Export(root+'\/cht.svg')\ncht.ExportAsFixedFormat(0,root+'\/cht.pdf')\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\/04\/2-26.jpg\" alt=\"\" class=\"wp-image-1197\" srcset=\"https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-26.jpg 880w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-26-300x258.jpg 300w, https:\/\/xlwings.net\/blog\/wp-content\/uploads\/2026\/04\/2-26-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-540","post","type-post","status-publish","format-standard","hentry","category-xlwings-chart"],"_links":{"self":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/540","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=540"}],"version-history":[{"count":2,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/540\/revisions"}],"predecessor-version":[{"id":1198,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/posts\/540\/revisions\/1198"}],"wp:attachment":[{"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/media?parent=540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/categories?post=540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xlwings.net\/blog\/wp-json\/wp\/v2\/tags?post=540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}