2. Setup Functions - jonboone1/plotlyPowerpoint Wiki

Original URL: https://github.com/jonboone1/plotlyPowerpoint/wiki/2.-Setup-Functions

Functions to use before creating slides

Set Template

Use setTemplate() to define the powerpoint template to be used in the create slides function. This takes one input, which is the path to the file.

 import plotlyPowerpoint as pp

Set Index for Individual Items

use setItemIndex() to tell this library which elements go where. For instance, if you are defining a title and description for each slide, you need to specify which placeholders represent the title and description in your powerpoint template. As of now, we only support slide, title, description, and chart.

Find the index for each element in the template you created.

#import package
from pptx import Presentation    

#load presentation
prs = Presentation("template.pptx")

#set the slide we are after - the first slide in the master layout is at index 0
slide = prs.slides.add_slide(prs.slide_layouts[0])

#print index and name
for shape in slide.placeholders:
    print('%d %s' % (shape.placeholder_format.idx, shape.name))

Now set the index for each item

#set global index for each item on template slide
pp.setItemIndex('slide', 0)
pp.setItemIndex("title", 0)
pp.setItemIndex("chart", 10)
pp.setItemIndex("description", 11)

Set Color Palette

use setColors() to define a custom color palette for charts. This must be defined as an array, colors will be used in order from top to bottom.

import plotly.express as px

#define custom color palette
colors = px.colors.qualitative.Vivid