Hi all,
I’m looking to plot charts in Excel from python. After some Googling
I’ve found the following code:
def plot(x, y, xAxisLog=False, yAxisLog=False) :
# acquire application object, which may start application
application = Dispatch("Excel .Application")
# create new file ('Workbook' in Excel-vocabulary)
workbook = application.Wor kbooks.Add()
# store default worksheet object so we can delete it later
defaultWorkshee t = workbook.Worksh eets(1)
# build new chart (on seperate page in workbook)
chart = workbook.Charts .Add()
print "chart", chart
chart.ChartType = constants.xlXYS catter
chart.Name = "Plot"
# create data worksheet
worksheet = workbook.Worksh eets.Add()
worksheet.Name = "Plot data"
# install data
xColumn = addDataColumn(w orksheet, 0, x)
yColumn = addDataColumn(w orksheet, 1, y)
# create series for chart
series = chart.SeriesCol lection().NewSe ries()
series.XValues = xColumn
series.Values = yColumn
series.Name = "Data"
series.MarkerSi ze = 3
# setup axises
xAxis = chart.Axes()[0]
yAxis = chart.Axes()[1]
xAxis.HasMajorG ridlines = True
yAxis.HasMajorG ridlines = True
if xAxisLog:
xAxis.ScaleType = constants.xlLog arithmic
if yAxisLog:
yAxis.ScaleType = constants.xlLog arithmic
# remove default worksheet
defaultWorkshee t.Delete()
# make stuff visible now.
chart.Activate( )
application.Vis ible = True
def genExcelName(ro w, col):
"""Translat e (0,0) into "A1"."""
if col < 26:
colName = chr(col + ord('A'))
else:
colName = chr((col / 26)-1 + ord('A')) + \
chr((col % 26) + ord('A'))
return "%s%s" % (colName, row + 1)
def addDataColumn(w orksheet, columnIdx, data):
range = worksheet.Range ("%s:%s" % (
genExcelName(0, columnIdx),
genExcelName(le n(data) - 1, columnIdx),
))
for idx, cell in enumerate(range ):
cell.Value = data[idx]
return range
# A simple example:
plot( (1,2,3,4,5), (6,7,8,9,10) )
I’m continually getting errors with:
chart.ChartType = constants.xlXYS catter
with
AttributeError: xlXYScatter
If I try other chart types, such as xl3DPieExploded , I still receive
the same error. Has anyone got any suggestions as to why it can’t seem
to find any chart types? I’m running WinXP, Python 2.5, latest PyWin32
and Excel 2007.
I don’t know who the original author of the above code is, it
defiantly wasn’t me, so major thanks to whoever it was. 1 8757 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael Jordan |
last post by:
I'm hoping that someone here can give me some insight into a problem I'm
running into with Python, pywin32 and Excel. All-in-all using Python and
pywin32 is great but I've run into a strange problem with the range Offset
property, I'm not getting the correct offset and the returned range is a
single cell and not the same size as the original range.
For example, when I enter the following lines of code in PythonWin :
from...
|
by: ian castleden |
last post by:
From time to time I see requests for some sort of python MS Excel
interface/software.
I have written just such software 100% python (works with Jython too! at
least it did a year ago).
It was once based (shamelessly) on the the Perl equivalent but now has gone
its own way.
It has been used in anger (i.e. people once payed me money to use it :-) and
includes both generation
and scaning of Excel files. There's even some documentation for...
|
by: mscir |
last post by:
Date: Thu, 08 Jul 2004 17:02:27 -0700
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <10ero4l3kp2qa65@corp.supernews.com>
Reply-To: mscir@usa.com
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@supernews.com
|
by: Mark Day |
last post by:
Hi All,
I am using Access 2000 to generate over 40 Excel charts and pivot tables
using early binding to the Excel 9.0 object library. I am finding that if I
show the Excel object while processing the charts, the whole process
completes in around 2 minutes. However if I hide the Excel object the same
process takes around 27 minutes to complete. I have played around with
screen updating and this makes no real difference to the time. Does...
|
by: Rach |
last post by:
Hi,
Does anyone know how to export charts/graphs from EXCEl
into Powerpoint-Microsoft Charts though VBA code. I would
like to import the underlying data with the chart as well.
I know we can paste as an Excel object in power point
which links the Excel file to the power point, but this
increases the file size.
Microsoft Power point has a feature called Microsoft
charts that allows to create charts and graphs in
| |
by: Takeadoe |
last post by:
I'm doubtful that the group is unbiased, but I will ask anyhow :o). If
one intends to plot lots of data, primarily XY line and scatter plots,
and mass produce them (in many cases I will be doing 88 graphs at a
time - 1 for each of 88 counties), will Exel be the best bet, or is
Access equally capable? I might mention that in time, I will be moving
all of my data into Access databases. I'm slowing learning charting
and automation in...
|
by: saragoesnuts |
last post by:
I have a program that automates to Excel with information in tables.
I want to add charts to the excel file (pie charts, bar charts, etc).
Is this possible?
|
by: Fred |
last post by:
Is it possible to generate a chart using the excel 2007 engine for a web
page? (output in jpg)...
If not what 3rd party solution would you recommend for this purpose
Thanks,
Fred
|
by: AGP |
last post by:
I have a VB6 application that has an OLE container with an embedded Excel
chart. Our office updated to Excel 2007 and now although the app works the
charts looks like crap. Since the app is fairly large my goal is to keep the
devlopement in VB6 but am open to any ideas or suggestions. What i want to
do is:
1. Keep my app in VB6 and find a workaround for the crappy looking charts.
the charts now look very blocky and the grid lines and...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |