简体   繁体   English

在 xlsxwriter 中交换 X 和 Y 轴

[英]Swap X and Y Axis in xlsxwriter

I just starting with XlsxWriter (0.8.4).我刚开始使用 XlsxWriter (0.8.4)。 I am trying to create charts but the x and y axis are not correct, I want to swap them, x for y.我正在尝试创建图表,但 x 和 y 轴不正确,我想交换它们,将 x 换成 y。 I'm using these code blocks to create the sheet and the chartsheet我正在使用这些代码块来创建工作表和图表

def new_sheet(self,sheetnm,sheetdata):
    self.ws = self.wb.add_worksheet(sheetnm)
    logging.info(self.ws)
    metadata = sheetdata[1]
    head = (colh[0] for colh in metadata)
    self.ws.write_row(0,0,head)
    rows = sheetdata[0]
    for ix,row in enumerate(rows):
        self.ws.write_row(ix+1,0,row)            

def new_chart(self,sheetnm,ctitle,xtitle,ytitle,rows,cols):
    self.cs = self.wb.add_chartsheet(sheetnm+"_chart")
    chart = self.wb.add_chart({'type': 'bar'})
    chart.set_title({'name': ctitle})
    for row in range(1,rows):
        chart.add_series({'categories':[sheetnm,0,1,0,cols-1],'values':[sheetnm,row,1,row,cols-1],'name':[sheetnm,row,0,row,0]})
    chart.set_x_axis({'name': xtitle})
    chart.set_y_axis({'name': ytitle})
    self.cs.set_chart(chart)

It is working, making the sheets.它正在工作,正在制作床单。 If I just use Excel to insert a chart, it inserts it with the expect x/y axis.如果我只是使用 Excel 插入图表,它会使用期望的 x/y 轴插入它。 How can I do the same?我怎样才能做同样的事情?

生成的图表表

[ [带数据的工作表[2]

已插入具有预期 X/Y 轴的图表

That worked great.那效果很好。 Thanks!谢谢! I'm not used to doing charts so the different types confuse me, column vs. vertical bar vs. horizontal bar.我不习惯做图表,所以不同类型的图表让我感到困惑,柱形、垂直条和水平条。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM