如何用Python在excel2003中绘制两个yax

2024-06-28 19:49:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Python和win32在excel2003的同一个绘图中绘制两个y轴不同的数据系列com.客户端. 我从VBA开始试图得到我需要的代码。以下是目前为止的情况:

chart = xlApp.Charts.Add()

# This part successfully creates the first series I want

series = chart.SeriesCollection(1)
series.XValues = xlSheet.Range("L13:L200")
series.Values = xlSheet.Range("M13:M200")

# This is what I added to try to plot the second series

series.AxisGroup = xlPrimary
series2 = chart.SeriesCollection(2)
series2.XValues = xlSheet.Range("L13:L200")
series2.Values = xlSheet.Range("N13:N200")
series2.AxisGroup = xlSecondary

# The rest is for formatting it the way I want, but it doesn't work now that I'm
# to plot the second series. (It stops working when I add the last five lines of code).

chart.Legend.Delete() # Delete legend; MUST BE DONE BEFORE CHART IS MOVED
series.Name = file
chart.Location(2, xlSheet.Name) # Copy chart to active worksheet
chart = xlSheet.Shapes(1)
chart.Top = 51
chart.Left = 240
chart.Width = 500
chart.Height = 350

这将绘制第一个系列,但如注释中所述,不再添加标题、移动图表、删除图例或调整图表大小。它与第二个系列无关。它也不会生成错误。在


Tags: thetochart绘制rangethisseriesvalues