Update docs/tech_docs/python/economics_presentation_sample.md
This commit is contained in:
@@ -1,146 +1,4 @@
|
||||
## Example Python PowerPoint Presentation
|
||||
|
||||
```python
|
||||
from pptx import Presentation
|
||||
from pptx.util import Inches, Pt
|
||||
from pptx.enum.shapes import MSO_SHAPE
|
||||
from pptx.dml.color import RGBColor
|
||||
|
||||
# Create a new Presentation object
|
||||
prs = Presentation()
|
||||
|
||||
# Slide 1: Title Slide
|
||||
slide_title_layout = prs.slide_layouts[0] # Choosing the title layout
|
||||
slide = prs.slides.add_slide(slide_title_layout)
|
||||
slide.shapes.title.text = "Economics 101"
|
||||
slide.placeholders[1].text = "An Introduction to Economics\nMacro and Micro Perspectives"
|
||||
|
||||
# Function to add slides
|
||||
def add_slide(prs, title, content):
|
||||
slide_layout = prs.slide_layouts[1] # Title and Content layout
|
||||
slide = prs.slides.add_slide(slide_layout)
|
||||
slide.shapes.title.text = title
|
||||
slide.placeholders[1].text = content
|
||||
return slide
|
||||
|
||||
# Slide 2: Introduction to Economics
|
||||
add_slide(prs, "Introduction to Economics", "Overview\nImportance of Economics\nMacro vs Micro")
|
||||
|
||||
# Slide 3: Macroeconomics Overview
|
||||
add_slide(prs, "Macroeconomics Overview", "Definition\nKey Concepts\nImportance")
|
||||
|
||||
# Slide 4: Microeconomics Overview
|
||||
add_slide(prs, "Microeconomics Overview", "Definition\nKey Concepts\nImportance")
|
||||
|
||||
# Slide 5: Fundamental Concepts
|
||||
add_slide(prs, "Fundamental Concepts", "Supply and Demand\nMarket Equilibrium\nElasticity")
|
||||
|
||||
# Slide 6: Macroeconomic Indicators
|
||||
add_slide(prs, "Macroeconomic Indicators", "GDP\nInflation Rate\nUnemployment Rate")
|
||||
|
||||
# Slide 7: Microeconomic Analysis
|
||||
add_slide(prs, "Microeconomic Analysis", "Consumer Behavior\nProduction and Costs\nMarket Structures")
|
||||
|
||||
# Slide 8: Monetary Policy
|
||||
add_slide(prs, "Monetary Policy", "Role of Central Bank\nTools of Monetary Policy\nImpact on Economy")
|
||||
|
||||
# Slide 9: Fiscal Policy
|
||||
add_slide(prs, "Fiscal Policy", "Government Spending\nTaxation\nImpact on Economy")
|
||||
|
||||
# Slide 10: International Trade
|
||||
add_slide(prs, "International Trade", "Benefits\nTrade Barriers\nTrade Agreements")
|
||||
|
||||
# Slide 11: Conclusion
|
||||
add_slide(prs, "Conclusion", "Summary of Key Points\nFurther Reading\nQuestions")
|
||||
|
||||
# Save the presentation
|
||||
prs.save("/mnt/data/Economics_101_Presentation.pptx")
|
||||
```
|
||||
---
|
||||
|
||||
from pptx.enum.text import PP_ALIGN
|
||||
from pptx.enum.chart import XL_CHART_TYPE
|
||||
|
||||
# Function to add a Section Header Slide
|
||||
def add_section_header_slide(prs, title):
|
||||
layout = prs.slide_layouts[5] # Using the 'section header' layout
|
||||
slide = prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
return slide
|
||||
|
||||
# Function to add a Two Content Slide
|
||||
def add_two_content_slide(prs, title, content_left, content_right):
|
||||
layout = prs.slide_layouts[3] # Using the 'Two Content' layout
|
||||
slide = prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
slide.placeholders[1].text = content_left
|
||||
slide.placeholders[2].text = content_right
|
||||
return slide
|
||||
|
||||
# Function to add a Comparison Slide
|
||||
def add_comparison_slide(prs, title, left_title, left_content, right_title, right_content):
|
||||
layout = prs.slide_layouts[2] # Using the 'Comparison' layout
|
||||
slide = prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
|
||||
# Left side
|
||||
shapes = slide.shapes
|
||||
title_shape_left = shapes.placeholders[1]
|
||||
title_shape_left.text = left_title
|
||||
content_shape_left = shapes.placeholders[2]
|
||||
content_shape_left.text = left_content
|
||||
|
||||
# Right side
|
||||
title_shape_right = shapes.placeholders[3]
|
||||
title_shape_right.text = right_title
|
||||
content_shape_right = shapes.placeholders[4]
|
||||
content_shape_right.text = right_content
|
||||
return slide
|
||||
|
||||
# Function to add a slide with a Chart
|
||||
def add_chart_slide(prs, title, chart_type, data):
|
||||
slide_layout = prs.slide_layouts[5] # Use the 'Title Slide' layout for simplicity
|
||||
slide = prs.slides.add_slide(slide_layout)
|
||||
slide.shapes.title.text = title
|
||||
|
||||
# Define chart data
|
||||
chart_data = Presentation().chart_data.ChartData()
|
||||
chart_data.categories = data["categories"]
|
||||
for name, values in data["series"].items():
|
||||
chart_data.add_series(name, values)
|
||||
|
||||
# Add the chart to the slide
|
||||
x, y, cx, cy = Inches(2), Inches(1.5), Inches(6), Inches(4.5)
|
||||
chart = slide.shapes.add_chart(
|
||||
chart_type, x, y, cx, cy, chart_data
|
||||
).chart
|
||||
|
||||
return slide
|
||||
|
||||
# Re-initialize the Presentation object to start fresh
|
||||
prs = Presentation()
|
||||
|
||||
# Adding different types of slides
|
||||
add_section_header_slide(prs, "Introduction to Economic Theories")
|
||||
add_two_content_slide(prs, "Supply and Demand", "Supply Explained", "Demand Explained")
|
||||
add_comparison_slide(prs, "Macroeconomics vs. Microeconomics", "Macroeconomics", "Overview of macroeconomic concepts", "Microeconomics", "Overview of microeconomic concepts")
|
||||
|
||||
# Chart data example
|
||||
chart_data_example = {
|
||||
"categories": ['2015', '2016', '2017', '2018', '2019'],
|
||||
"series": {
|
||||
"Series 1": (19.2, 21.4, 16.7, 18.3, 17.9),
|
||||
"Series 2": (22.3, 28.6, 15.2, 21.8, 20.1),
|
||||
}
|
||||
}
|
||||
add_chart_slide(prs, "Economic Growth Over Time", XL_CHART_TYPE.COLUMN_CLUSTERED, chart_data_example)
|
||||
|
||||
# Save the presentation with commonly used slide designs
|
||||
prs.save("/mnt/data/Common_Slide_Designs_Presentation.pptx")
|
||||
|
||||
"/mnt/data/Common_Slide_Designs_Presentation.pptx"
|
||||
|
||||
---
|
||||
## Sample Economic PowerPoint Presentation
|
||||
|
||||
```python
|
||||
from pptx import Presentation
|
||||
@@ -148,62 +6,119 @@ from pptx.util import Inches, Pt
|
||||
from pptx.enum.shapes import MSO_SHAPE
|
||||
from pptx.enum.chart import XL_CHART_TYPE
|
||||
from pptx.chart.data import CategoryChartData
|
||||
from pptx.dml.color import RGBColor
|
||||
|
||||
# Initialize a new Presentation
|
||||
prs = Presentation()
|
||||
class PresentationCreator:
|
||||
"""
|
||||
A class to create PowerPoint presentations with predefined slide templates.
|
||||
|
||||
Attributes:
|
||||
prs (Presentation): A python-pptx Presentation object.
|
||||
title (str): The title of the presentation.
|
||||
"""
|
||||
def __init__(self, title="Presentation"):
|
||||
"""
|
||||
Initializes the PresentationCreator with a title for the presentation.
|
||||
|
||||
Args:
|
||||
title (str): The title of the presentation.
|
||||
"""
|
||||
self.prs = Presentation()
|
||||
self.title = title
|
||||
|
||||
def add_section_header_slide(self, title):
|
||||
"""
|
||||
Adds a section header slide with a given title.
|
||||
|
||||
Args:
|
||||
title (str): The title of the section.
|
||||
"""
|
||||
layout = self.prs.slide_layouts[1] # Use Title and Content layout
|
||||
slide = self.prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
# Set a subtitle or a short description in the content placeholder if needed
|
||||
|
||||
def add_two_content_slide(self, title, left_content, right_content):
|
||||
"""
|
||||
Adds a slide with a title and two content sections side by side.
|
||||
|
||||
Args:
|
||||
title (str): The title of the slide.
|
||||
left_content (str): The content for the left section.
|
||||
right_content (str): The content for the right section.
|
||||
"""
|
||||
layout = self.prs.slide_layouts[1] # Reuse Title and Content layout
|
||||
slide = self.prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
slide.placeholders[1].text = left_content # Placeholder for left content
|
||||
# Note: For a true side-by-side layout, consider adding a textbox or customizing the layout
|
||||
|
||||
def add_comparison_slide(self, title, content):
|
||||
"""
|
||||
Adds a slide designed for comparisons.
|
||||
|
||||
Note: This example simplifies to a single content area for demonstration.
|
||||
|
||||
Args:
|
||||
title (str): The title of the slide.
|
||||
content (str): The content for comparison.
|
||||
"""
|
||||
layout = self.prs.slide_layouts[1] # Simplified use of Title and Content layout
|
||||
slide = self.prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
slide.placeholders[1].text = content # Placeholder for comparison content
|
||||
|
||||
def add_chart_slide(self, title, data):
|
||||
"""
|
||||
Adds a slide with a chart based on provided data.
|
||||
|
||||
Args:
|
||||
title (str): The title of the slide.
|
||||
data (dict): The data for the chart, including categories and series.
|
||||
"""
|
||||
slide_layout = self.prs.slide_layouts[5] # Use Title Only layout for more chart space
|
||||
slide = self.prs.slides.add_slide(slide_layout)
|
||||
slide.shapes.title.text = title
|
||||
|
||||
chart_data = CategoryChartData()
|
||||
chart_data.categories = data["categories"]
|
||||
for name, values in data["series"].items():
|
||||
chart_data.add_series(name, values)
|
||||
|
||||
x, y, cx, cy = Inches(2), Inches(1.5), Inches(6), Inches(4.5)
|
||||
chart = slide.shapes.add_chart(
|
||||
XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
|
||||
).chart
|
||||
# Chart style and colors can be customized further
|
||||
|
||||
def save_presentation(self, filename="presentation.pptx"):
|
||||
"""
|
||||
Saves the presentation to a file.
|
||||
|
||||
Args:
|
||||
filename (str): The filename or path to save the presentation.
|
||||
"""
|
||||
self.prs.save(filename)
|
||||
|
||||
# Adding a Section Header Slide
|
||||
def add_section_header_slide(title):
|
||||
layout = prs.slide_layouts[1] # Title and Content layout for simplicity
|
||||
slide = prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
|
||||
# Adding a Two Content Slide
|
||||
def add_two_content_slide(title, left_content, right_content):
|
||||
layout = prs.slide_layouts[1] # Reuse Title and Content layout
|
||||
slide = prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
slide.placeholders[1].text = left_content # Using only one placeholder for simplicity
|
||||
# For actual left/right content, consider using shapes or adjusting the layout
|
||||
|
||||
# Adding a Comparison Slide
|
||||
# Simplifying to use available placeholders correctly
|
||||
def add_comparison_slide(title, content):
|
||||
layout = prs.slide_layouts[1] # Reuse Title and Content layout
|
||||
slide = prs.slides.add_slide(layout)
|
||||
slide.shapes.title.text = title
|
||||
slide.placeholders[1].text = content # Simplified content
|
||||
|
||||
# Adding a Chart Slide
|
||||
def add_chart_slide(title, data):
|
||||
slide_layout = prs.slide_layouts[5] # Use Title Only layout
|
||||
slide = prs.slides.add_slide(slide_layout)
|
||||
slide.shapes.title.text = title
|
||||
|
||||
chart_data = CategoryChartData()
|
||||
chart_data.categories = data["categories"]
|
||||
for name, values in data["series"].items():
|
||||
chart_data.add_series(name, values)
|
||||
|
||||
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
|
||||
chart = slide.shapes.add_chart(
|
||||
XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
|
||||
).chart
|
||||
|
||||
# Usage Examples
|
||||
add_section_header_slide("Introduction to Economics")
|
||||
add_two_content_slide("Supply and Demand", "Supply Side Analysis", "Demand Side Analysis")
|
||||
add_comparison_slide("Economic Models", "Comparison of Various Economic Models")
|
||||
chart_data_example = {
|
||||
"categories": ['2015', '2016', '2017', '2018', '2019'],
|
||||
"series": {
|
||||
"GDP Growth": (2.5, 2.9, 2.3, 3.1, 2.2),
|
||||
"Inflation Rate": (1.5, 1.8, 2.1, 1.9, 1.6),
|
||||
# Example usage
|
||||
if __name__ == "__main__":
|
||||
creator = PresentationCreator("Economics 101 Presentation")
|
||||
|
||||
# Adding slides
|
||||
creator.add_section_header_slide("Introduction to Economic Theories")
|
||||
creator.add_two_content_slide("Supply and Demand", "Supply Side Analysis", "Demand Side Analysis")
|
||||
creator.add_comparison_slide("Economic Models", "Comparative Analysis")
|
||||
|
||||
# Chart data example for economic indicators
|
||||
chart_data_example = {
|
||||
"categories": ['2015', '2016', '2017', '2018', '2019'],
|
||||
"series": {
|
||||
"GDP Growth": (2.5, 2.9, 2.3, 3.1, 2.2),
|
||||
"Inflation Rate": (1.5, 1.8, 2.1, 1.9, 1.6),
|
||||
}
|
||||
}
|
||||
}
|
||||
add_chart_slide("Economic Indicators Over Time", chart_data_example)
|
||||
|
||||
# Save the presentation
|
||||
presentation_path = "/mnt/data/Revised_Economic_Presentation.pptx"
|
||||
prs.save(presentation_path)
|
||||
```
|
||||
creator.add_chart_slide("Economic Indicators Over Time", chart_data_example)
|
||||
|
||||
# Saving the presentation
|
||||
creator.save_presentation("./Economics_101_Presentation.pptx")
|
||||
```
|
||||
Reference in New Issue
Block a user