[英]Is there a way to create a chart in XlsxWriter without writing the data to cells in a sheet? IE. From an array in the python script?
My goal is to create a chart in a sheet from XlsxWriter without having the data from the chart available anywhere on the sheet (I don't want to reference cells).我的目标是在 XlsxWriter 的工作表中创建一个图表,而无需在工作表上的任何位置提供图表中的数据(我不想引用单元格)。 For legal reasons the data cannot be available in the book.
由于法律原因,书中无法提供数据。
Alternatively, if there's a way to write data to cells, graph that data, and then remove the cell references so I can have a graph that isn't referencing cells, I would be open to that as well.或者,如果有一种方法可以将数据写入单元格,绘制该数据,然后删除单元格引用,以便我可以有一个不引用单元格的图表,我也会对此持开放态度。 I know there are some ways to accomplish this in excel.
我知道在 excel 中有一些方法可以做到这一点。
I have tried replacing the 'categories' and 'values' arguments with lists of integers (data I want graphed) but I get an error for a lack of cell references.我尝试用整数列表(我想要绘制的数据)替换“类别”和“值”arguments,但由于缺少单元格引用而出现错误。 (See function below).
(参见下面的 function)。
# Builds a chart with top left corner at row_start, col_start (zero
# indexed).
# data[data_input[i][0]]['history'][0] is a list of dates.
# data[data_input[i][0]]['history'][1] is a list of values for those dates.
chart = workbook.add_chart({'type': 'line'})
for i in range(len(data_input)):
chart.add_series({
'name': title,
'categories': data[data_input[i][0]]['history'][0],
'values': data[data_input[i][0]]['history'][1],
'line': {'color': colors[i], 'width': 1}
})
worksheet.insert_chart(row_start, col_start, chart)
TypeError: xl_range_formula() takes 5 positional arguments but 261 were given TypeError: xl_range_formula() 需要 5 个位置 arguments 但给出了 261
My goal is to create a chart in a sheet from XlsxWriter without having the data from the chart available anywhere on the sheet.
我的目标是在 XlsxWriter 的工作表中创建图表,而无需在工作表上的任何位置使用图表中的数据。 For legal reasons the data cannot be available in the book.
由于法律原因,书中无法提供数据。
That isn't possible.那是不可能的。
In Excel it is possible to draw a graph from data that you supply directly in the data dialog without referring to cells.在 Excel 中,可以根据您直接在数据对话框中提供的数据绘制图形,而无需引用单元格。 However, that option isn't supported by XlsxWriter and it also doesn't hide your data in any way since anyone can go into the dialog and see the data.
但是,XlsxWriter 不支持该选项,并且它也不会以任何方式隐藏您的数据,因为任何人都可以进入对话框查看数据。 Also, anyone could unzip the file and see the data.
此外,任何人都可以解压缩文件并查看数据。
Also, anyone could mouse over the data in the chart and see the values that it is generated from.此外,任何人都可以将鼠标悬停在图表中的数据上并查看生成数据的值。
Alternatively, if there's a way to write data to cells, graph that data, and then remove the cell references so I can have a graph that isn't referencing cells,
或者,如果有一种方法可以将数据写入单元格,绘制该数据的图形,然后删除单元格引用,这样我就可以得到一个不引用单元格的图形,
No, for the same reasons as above.不,出于与上述相同的原因。
Take a step back and try to figure out if what you want to do is possible in any way just in Excel (possibly by hiding a worksheet with the source data and then locking and password protecting the file).退后一步,尝试弄清楚您是否可以仅在 Excel 中以任何方式执行操作(可能通过隐藏包含源数据的工作表,然后锁定和密码保护文件)。 If there is a way to do it in Excel then you know the question to ask about how to do it in Python.
如果有一种方法可以在 Excel 中执行此操作,那么您知道要询问如何在 Python 中执行此操作的问题。
As a suggestion, one way to do it could be to create an image of a chart and insert that into Excel.作为建议,一种方法是创建图表的图像并将其插入到 Excel 中。 That way there is no link to the original data.
这样就没有原始数据的链接。
One option is to save the chart as an image and insert the image to your excel worksheet using xlsxwriter's insert_image一种选择是将图表保存为图像并使用 xlsxwriter 的 insert_image 将图像插入到 excel 工作表中
plot = your_df.plot()
fig = plot.get_figure()
fig.savefig("output.png")
# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('images.xlsx')
worksheet = workbook.add_worksheet()
worksheet.insert_image('B2', 'output.png')
saving the plot保存 plot
Saving plots (AxesSubPlot) generated from python pandas with matplotlib's savefig 使用 matplotlib 的 savefig 保存从 python pandas 生成的图(AxesSubPlot)
inserting the image插入图像
https://xlsxwriter.readthedocs.io/example_images.html https://xlsxwriter.readthedocs.io/example_images.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.