Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use matplotlib to draw and write directly to excel

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to use matplotlib to draw directly into excel, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Use matpyplot.lib to generate pictures, want to write directly to excel inside.

As a result, he didn't touch the door and wasted a little time.

I took a look at the document by the way.

A few examples are given by the way. I hope I can help you.

Import os, sys

From matplotlib import pyplot as plt

Import pandas as pd

From io import BytesIO

Import xlswriter as xls

> df3 = pd.DataFrame ({'Xrays: [' Aids, 'Balls,' Aids,'B'],'Y': [1,4,3,2]})

> df3

X Y

0 A 1

1 B 4

2 A 3

3 B 2

Df3.plot ()

Plt.show ()

Plt.savefig ('abc.png')

Book=xls.Workbook ('abc.xls')

Sheet=book.add_worksheet ('demo')

Sheet.insert_image ('D5boys,' abc.png')

Book.close ()

The picture is written in Excel.

Of course。 It's right here.

Insert_image (row,column, imagfile, {xargs})

Dictionary xargs

{"object_position':" off-set: 0, "y" off-set: 0, "x" scale: 1, "y" scale: 1, 'object_position': 2,' image_data': None, 'url': None,' tip': None,}

Here's an image_data. This is a buffer. Or an object of byteio.

In this way, you don't have to write to the disk first and then read and write excel from the disk.

Imagdata=BytesIO ()

Plt.savefig (imagedata)

Book=xls.Workbook ('abc.xls')

Sheet=book.add_worksheet ('demo')

Sheet.insert_image (10 and 5), {"image_data": imagedata})

Book.close ()

The effect is the same.

In fact, this can solve the problem perfectly.

The above is all the contents of the article "how to use matplotlib to draw and write directly to excel". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report