我的数据框如下
Period Backed Closed Failed Successful total
0 2015_November 1 0 0 7 8
1 2015_December 0 0 0 30 30
2 2016_January 0 1 0 46 47
3 2016_February 0 0 2 72 74
4 2016_March 0 1 0 56 57
5 2016_April 1 0 0 52 53
6 2016_May 2 4 1 50 57
7 2016_June 2 2 2 102 108
8 2016_July 0 0 0 10 10
10 Grand_total 6 8 5 425 444
我可以使用Period
x-axis
和Backed
,Closed
,Failed
,Successful
为Y轴使用以下代码绘制正确的图表
# Create a chart object.
chart = workbook.add_chart({'type': 'column'})
# Configure the series of the chart from the dataframe data.
for col_num in range(2, len(df3.columns) ):
chart.add_series({
'name': ['modified_data', 0, col_num],
'categories': ['modified_data', 1, 1, (len(df3.index) - 1 ), 1], # rows , columns
'values': ['modified_data', 1, col_num, (len(df3.index) - 1 ), col_num],
'fill': {'color': brews['Spectral'][col_num - 1]},
'gap': 200,
})
# Insert the chart into the worksheet.
ws2.insert_chart('B14', chart)
这是图表:
但是,我要求将Period
分隔为Year
和' Month
,然后将其用作x轴上的Backed Closed Failed Successful total
在y轴上。
我将它们分成新的数据框,如下所示。
Year Start_Month Backed Closed Failed Successful total
0 2015 November 1 0 0 7 8
1 2015 December 0 0 0 30 30
2 2016 January 0 1 0 46 47
3 2016 February 0 0 2 72 74
4 2016 March 0 1 0 56 57
5 2016 April 1 0 0 52 53
6 2016 May 2 4 1 50 57
7 2016 June 2 2 2 102 108
8 2016 July 0 0 0 10 10
10 Grand Total 6 8 5 425 444
然而,我无法使用charts
找到多x轴到多y轴图的解决方案,这将生成与上面相同的图。
我们可以合并Year and Start_Month
并将其用作x-axis
仅用于绘图目的吗?在excel-data上,它仍将显示为两个单独的列。
欢迎提出任何指示。