This is my result can ypu just add diagram in it to show my stasts line bar graph line diagram or pia chart what ever is suitable for it
python3 -c " from docx import Document doc = Document('/tmp/workspace/attachments/9f58a56b-d5dc-4834-b3d4-1b1c2a014d0b/aditi final result mpt.docx') for p in doc.paragraphs: style = p.style.name if p.style else 'None' if p.text.strip(): print(f'[{style}] {p.text}') print('\n--- TABLES ---') for i, table in enumerate(doc.tables): print(f'\nTable {i+1}:') for row in table.rows: row_data = [cell.text.strip() for cell in row.cells] print(row_data) "
python3 << 'EOF' import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import matplotlib.patches as mpatches import numpy as np import os os.makedirs('/tmp/workspace/aditi-charts', exist_ok=True) # ── CHART 1: Grouped Bar – Pre vs Post for all 3 outcomes ────────────────── fig, axes = plt.subplots(1, 3, figsize=(14, 6)) fig.suptitle('Pre vs Post Intervention Comparison\n(Hypopressive Exercises, n = 25)', fontsize=14, fontweight='bold', y=1.01) data = [ ('TUG Test\n(Mobility)', 'Time (seconds)', 10.92, 1.55, 10.08, 1.34, 'Lower = Better', True), ('Pressure Biofeedback\n(Core Strength)', 'PBF Value (mmHg)', 66.24, 1.67, 63.68, 1.11, 'Closer to 60 = Better', True), ('PF-10\n(Physical Function)', 'PF-10 Score', 75.20, 5.68, 77.80, 4.10, 'Higher = Better', False), ] colors_pre = '#4472C4' colors_post = '#ED7D31' for ax, (label, ylabel, pre_m, pre_sd, post_m, post_sd, note, lower_better) in zip(axes, data): bars = ax.bar(['Pre', 'Post'], [pre_m, post_m], color=[colors_pre, colors_post], width=0.45, edgecolor='white', linewidth=0.8) ax.errorbar(['Pre', 'Post'], [pre_m, post_m], yerr=[pre_sd, post_sd], fmt='none', color='black', capsize=6, linewidth=1.5) ax.set_title(label, fontsize=11, fontweight='bold') ax.set_ylabel(ylabel, fontsize=9) ax.set_xlabel('Test Point', fontsize=9) # annotate bars for bar, val in zip(bars, [pre_m, post_m]): ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + pre_sd*0.15, f'{val}', ha='center', va='bottom', fontsize=10, fontweight='bold') # p-value annotation x1, x2 = 0, 1 y_max = max(pre_m + pre_sd, post_m + post_sd) * 1.08 ax.annotate('', xy=(x2, y_max), xytext=(x1, y_max), arrowprops=dict(arrowstyle='-', color='black', lw=1.2)) ax.text((x1+x2)/2, y_max * 1.005, 'p < 0.001', ha='center', va='bottom', fontsize=9, color='red') ax.set_ylim(0, y_max * 1.15) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.text(0.5, -0.18, note, ha='center', va='top', fontsize=8, fontstyle='italic', color='gray', transform=ax.transAxes) pre_patch = mpatches.Patch(color=colors_pre, label='Pre-Intervention') post_patch = mpatches.Patch(color=colors_post, label='Post-Intervention') fig.legend(handles=[pre_patch, post_patch], loc='lower center', ncol=2, fontsize=10, frameon=False, bbox_to_anchor=(0.5, -0.04)) plt.tight_layout() plt.savefig('/tmp/workspace/aditi-charts/chart1_grouped_bar.png', dpi=180, bbox_inches='tight') plt.close() print("Chart 1 saved") # ── CHART 2: Horizontal Bar – Mean Improvement ───────────────────────────── fig, ax = plt.subplots(figsize=(9, 4.5)) outcomes = ['TUG Test\n(Mobility)', 'Pressure Biofeedback\n(Core Strength)', 'PF-10\n(Physical Function)'] improvements = [0.84, 2.56, 2.60] errors = [0.47, 1.23, 2.55] bar_colors = ['#5B9BD5', '#70AD47', '#FF8C00'] units = ['sec', 'mmHg', 'points'] bars = ax.barh(outcomes, improvements, xerr=errors, color=bar_colors, edgecolor='white', linewidth=0.8, capsize=5, height=0.45) for bar, val, unit in zip(bars, improvements, units): ax.text(val + 0.05, bar.get_y() + bar.get_height()/2, f' {val} {unit} (p < 0.001)', va='center', fontsize=9, fontweight='bold') ax.set_xlabel('Mean Improvement after 4 Weeks', fontsize=11) ax.set_title('Mean Improvement in Outcome Measures\nafter 4-Week Hypopressive Exercise Program', fontsize=12, fontweight='bold') ax.set_xlim(0, 8) ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.axvline(0, color='black', linewidth=0.8) plt.tight_layout() plt.savefig('/tmp/workspace/aditi-charts/chart2_improvement_bar.png', dpi=180, bbox_inches='tight') plt.close() print("Chart 2 saved") # ── CHART 3: Pie Chart – % improvement for each outcome ──────────────────── fig, axes = plt.subplots(1, 3, figsize=(13, 5)) fig.suptitle('Percentage Improvement After 4-Week Hypopressive Exercise Program', fontsize=13, fontweight='bold') pie_data = [ ('TUG Test\n(Mobility)', 7.69, 92.31, '7.7% improvement'), ('Pressure Biofeedback\n(Core)', 3.87, 96.13, '3.9% improvement'), ('PF-10\n(Physical Function)', 3.46, 96.54, '3.5% improvement'), ] for ax, (title, imp_pct, rem_pct, note) in zip(axes, pie_data): wedges, texts, autotexts = ax.pie( [imp_pct, rem_pct], labels=['Improved', 'Remaining\nBaseline'], colors=['#ED7D31', '#BDD7EE'], autopct='%1.1f%%', startangle=90, wedgeprops=dict(edgecolor='white', linewidth=1.5), textprops=dict(fontsize=9) ) autotexts[0].set_fontweight('bold') autotexts[0].set_color('white') ax.set_title(title, fontsize=10, fontweight='bold') plt.tight_layout() plt.savefig('/tmp/workspace/aditi-charts/chart3_pie.png', dpi=180, bbox_inches='tight') plt.close() print("Chart 3 saved") print("All 3 charts saved successfully.") EOF
python3 << 'EOF' from docx import Document from docx.shared import Inches, Pt, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement import copy src = '/tmp/workspace/attachments/9f58a56b-d5dc-4834-b3d4-1b1c2a014d0b/aditi final result mpt.docx' out = '/tmp/workspace/aditi-charts/aditi_final_result_with_charts.docx' doc = Document(src) chart1 = '/tmp/workspace/aditi-charts/chart1_grouped_bar.png' chart2 = '/tmp/workspace/aditi-charts/chart2_improvement_bar.png' chart3 = '/tmp/workspace/aditi-charts/chart3_pie.png' def add_figure(doc, img_path, caption_text): """Add a centered image with a caption paragraph below it.""" p = doc.add_paragraph() p.alignment = WD_ALIGN_PARAGRAPH.CENTER run = p.add_run() run.add_picture(img_path, width=Inches(5.8)) cap = doc.add_paragraph(caption_text) cap.alignment = WD_ALIGN_PARAGRAPH.CENTER cap_run = cap.runs[0] cap_run.font.size = Pt(9) cap_run.font.italic = True cap_run.font.color.rgb = RGBColor(0x44, 0x47, 0x2C) doc.add_paragraph('') # spacing # ── Find insertion points ────────────────────────────────────────────────── # We'll insert charts AFTER specific headings/paragraphs # Strategy: rebuild paragraphs list with chart injections at right places # Identify paragraph indices for insertion para_texts = [p.text.strip() for p in doc.paragraphs] # We will add charts after: # 1. After section 4.7 table note (Table 4.3 note paragraph) → Chart 1 (grouped bar) # 2. After Chart 1 → Chart 2 (improvement bar) # 3. After Chart 2 → Chart 3 (pie) # The cleanest way: append charts at the end of the document # (before summary or after 4.7 section) using paragraph element manipulation # Find the paragraph with "4.8 Summary of Results" heading target_idx = None for i, p in enumerate(doc.paragraphs): if '4.8' in p.text and 'Summary' in p.text: target_idx = i break print(f"Found 4.8 heading at paragraph index: {target_idx}") def insert_paragraph_before(paragraph, doc): """Return a new paragraph inserted just before the given paragraph.""" new_para = OxmlElement('w:p') paragraph._element.addprevious(new_para) from docx.text.paragraph import Paragraph return Paragraph(new_para, paragraph._element.getparent()) def insert_picture_before(paragraph, img_path, caption, doc, width=Inches(5.8)): """Insert an image + caption as new paragraphs just before the given paragraph.""" # Insert image paragraph img_para_el = OxmlElement('w:p') paragraph._element.addprevious(img_para_el) from docx.text.paragraph import Paragraph img_para = Paragraph(img_para_el, doc.element.body) img_para.alignment = WD_ALIGN_PARAGRAPH.CENTER run = img_para.add_run() run.add_picture(img_path, width=width) # Insert caption paragraph cap_para_el = OxmlElement('w:p') paragraph._element.addprevious(cap_para_el) cap_para = Paragraph(cap_para_el, doc.element.body) cap_para.alignment = WD_ALIGN_PARAGRAPH.CENTER cap_run = cap_para.add_run(caption) cap_run.font.size = Pt(9) cap_run.font.italic = True # Spacing paragraph sp_el = OxmlElement('w:p') paragraph._element.addprevious(sp_el) # Identify paragraph for section 4.8 summary_para = doc.paragraphs[target_idx] # Insert all 3 charts before section 4.8 insert_picture_before( summary_para, chart3, 'Figure 3: Pie Charts Showing Percentage Improvement in Each Outcome Measure After 4-Week Hypopressive Exercise Program', doc, width=Inches(6.0) ) insert_picture_before( summary_para, chart2, 'Figure 2: Mean Improvement (with SD error bars) in TUG, PBF, and PF-10 Scores After 4-Week Hypopressive Exercise Program', doc, width=Inches(5.8) ) insert_picture_before( summary_para, chart1, 'Figure 1: Grouped Bar Charts Showing Pre vs Post Intervention Mean Scores (±SD) for TUG Test, Pressure Biofeedback, and PF-10 (n=25). *p < 0.001 for all outcomes.', doc, width=Inches(6.2) ) doc.save(out) print(f"Document saved to: {out}") EOF
python3 << 'EOF' from docx import Document from docx.shared import Inches, Pt, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement import copy src = '/tmp/workspace/attachments/9f58a56b-d5dc-4834-b3d4-1b1c2a014d0b/aditi final result mpt.docx' out = '/tmp/workspace/aditi-charts/aditi_final_result_with_charts.docx' chart1 = '/tmp/workspace/aditi-charts/chart1_grouped_bar.png' chart2 = '/tmp/workspace/aditi-charts/chart2_improvement_bar.png' chart3 = '/tmp/workspace/aditi-charts/chart3_pie.png' doc = Document(src) # Find section 4.8 heading paragraph index inside body elements # We'll use a different strategy: find the XML element for 4.8, then insert before it body = doc.element.body # Find the 4.8 heading XML element target_elem = None for elem in body: tag = elem.tag.split('}')[-1] if '}' in elem.tag else elem.tag if tag == 'p': text = ''.join(r.text or '' for r in elem.iter(qn('w:t'))) if '4.8' in text and 'Summary' in text: target_elem = elem break print("Found target:", target_elem is not None) def make_pic_paragraph(doc_part, img_path, width_emu): """Build a <w:p> XML element containing a centered picture run.""" from docx.oxml.ns import nsmap import docx.oxml # Use the document part to add the image relationship image_part, rId = doc_part.get_or_add_image(img_path) # Build pic XML inline from docx.oxml import parse_xml from docx.opc.constants import RELATIONSHIP_TYPE as RT cx = width_emu cy_dummy = int(width_emu * 0.45) # approximate height pic_xml = f'''<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> <w:pPr><w:jc w:val="center"/></w:pPr> <w:r> <w:rPr/> <w:drawing> <wp:inline distT="0" distB="0" distL="0" distR="0"> <wp:extent cx="{cx}" cy="{cy_dummy}"/> <wp:effectExtent l="0" t="0" r="0" b="0"/> <wp:docPr id="1" name="Picture"/> <wp:cNvGraphicFramePr> <a:graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1"/> </wp:cNvGraphicFramePr> <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"> <pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"> <pic:nvPicPr> <pic:cNvPr id="0" name="image"/> <pic:cNvPicPr/> </pic:nvPicPr> <pic:blipFill> <a:blip r:embed="{rId}"/> <a:stretch><a:fillRect/></a:stretch> </pic:blipFill> <pic:spPr> <a:xfrm><a:off x="0" y="0"/><a:ext cx="{cx}" cy="{cy_dummy}"/></a:xfrm> <a:prstGeom prst="rect"><a:avLst/></a:prstGeom> </pic:spPr> </pic:pic> </a:graphicData> </a:graphic> </wp:inline> </w:drawing> </w:r> </w:p>''' return parse_xml(pic_xml) def make_caption_paragraph(text): """Build a centered italic caption <w:p>.""" from docx.oxml import parse_xml cap_xml = f'''<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> <w:pPr><w:jc w:val="center"/></w:pPr> <w:r> <w:rPr><w:i/><w:sz w:val="18"/><w:color w:val="595959"/></w:rPr> <w:t xml:space="preserve">{text}</w:t> </w:r> </w:p>''' return parse_xml(cap_xml) def make_spacing_paragraph(): from docx.oxml import parse_xml return parse_xml('<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"/>') # Insert before section 4.8 (order: insert in reverse so each goes just before target) EMU_PER_INCH = 914400 charts = [ (chart3, 'Figure 3: Pie Charts – Percentage Improvement in Each Outcome Measure After 4-Week Hypopressive Exercise Program', int(6.0 * EMU_PER_INCH)), (chart2, 'Figure 2: Mean Improvement (±SD) in TUG, PBF, and PF-10 After 4-Week Hypopressive Exercises', int(5.8 * EMU_PER_INCH)), (chart1, 'Figure 1: Pre vs Post Intervention Mean Scores (±SD) for All 3 Outcome Measures (n=25). *p < 0.001', int(6.2 * EMU_PER_INCH)), ] doc_part = doc.part for img_path, caption, width_emu in charts: # Insert spacing sp = make_spacing_paragraph() target_elem.addprevious(sp) # Insert caption cap_elem = make_caption_paragraph(caption) target_elem.addprevious(cap_elem) # Insert picture pic_elem = make_pic_paragraph(doc_part, img_path, width_emu) target_elem.addprevious(pic_elem) # Insert spacing before image sp2 = make_spacing_paragraph() target_elem.addprevious(sp2) doc.save(out) print(f"Saved: {out}") EOF
python3 << 'EOF' """ Use the unpack/repack approach from the DOCX skill to insert images. We'll use python-docx's proper Document.add_picture approach by appending to the document and then reordering paragraph elements. """ from docx import Document from docx.shared import Inches, Pt, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement import copy src = '/tmp/workspace/attachments/9f58a56b-d5dc-4834-b3d4-1b1c2a014d0b/aditi final result mpt.docx' out = '/tmp/workspace/aditi-charts/aditi_final_result_with_charts.docx' chart1 = '/tmp/workspace/aditi-charts/chart1_grouped_bar.png' chart2 = '/tmp/workspace/aditi-charts/chart2_improvement_bar.png' chart3 = '/tmp/workspace/aditi-charts/chart3_pie.png' doc = Document(src) body = doc.element.body # --- Step 1: append charts at the END of doc (python-docx API works fine here) def add_figure_to_doc(doc, img_path, caption_text, width_inches=6.0): p_img = doc.add_paragraph() p_img.alignment = WD_ALIGN_PARAGRAPH.CENTER run = p_img.add_run() run.add_picture(img_path, width=Inches(width_inches)) p_cap = doc.add_paragraph(caption_text) p_cap.alignment = WD_ALIGN_PARAGRAPH.CENTER for run in p_cap.runs: run.font.size = Pt(9) run.font.italic = True run.font.color.rgb = RGBColor(0x59, 0x59, 0x59) doc.add_paragraph() # spacing charts_to_add = [ (chart1, 'Figure 1: Pre vs Post Intervention Mean Scores (±SD) for TUG Test, Pressure Biofeedback, and PF-10 (n=25). All outcomes: p<0.001.', 6.2), (chart2, 'Figure 2: Mean Improvement (±SD) in TUG, PBF, and PF-10 Scores After 4-Week Hypopressive Exercise Program.', 5.8), (chart3, 'Figure 3: Pie Charts Showing Percentage Improvement in Each Outcome Measure After 4-Week Hypopressive Exercise Program.', 6.0), ] # Record how many elements are in body before adding body_count_before = len(body) for img, cap, w in charts_to_add: add_figure_to_doc(doc, img, cap, w) # --- Step 2: Move those appended elements to just before the 4.8 heading # Find target (4.8 Summary) in body target_elem = None for elem in body: tag = elem.tag.split('}')[-1] if '}' in elem.tag else elem.tag if tag == 'p': text = ''.join(r.text or '' for r in elem.iter(qn('w:t'))) if '4.8' in text and 'Summary' in text: target_elem = elem break print("Target found:", target_elem is not None) print("Body length before move:", len(body)) # Collect newly appended elements (everything from body_count_before onward) new_elements = list(body)[body_count_before:] print(f"Elements to move: {len(new_elements)}") # Remove them from current position and insert before target for elem in new_elements: body.remove(elem) for elem in new_elements: target_elem.addprevious(elem) doc.save(out) print(f"Saved: {out}") EOF
python3 -c " from docx import Document doc = Document('/tmp/workspace/aditi-charts/aditi_final_result_with_charts.docx') for i, p in enumerate(doc.paragraphs): if p.text.strip(): print(f'{i}: {p.text[:80]}') else: has_pic = any(r._element.find('.//{http://schemas.openxmlformats.org/drawingml/2006/main}blip') is not None for r in p.runs) if has_pic: print(f'{i}: [IMAGE PARAGRAPH]') "
python3 << 'EOF' """Fixed version: image first, then caption below it.""" from docx import Document from docx.shared import Inches, Pt, RGBColor from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.oxml import OxmlElement src = '/tmp/workspace/attachments/9f58a56b-d5dc-4834-b3d4-1b1c2a014d0b/aditi final result mpt.docx' out = '/tmp/workspace/aditi-charts/aditi_final_result_with_charts.docx' chart1 = '/tmp/workspace/aditi-charts/chart1_grouped_bar.png' chart2 = '/tmp/workspace/aditi-charts/chart2_improvement_bar.png' chart3 = '/tmp/workspace/aditi-charts/chart3_pie.png' doc = Document(src) body = doc.element.body def add_figure_block(doc, img_path, caption_text, width_inches=6.0): """Add spacing, image, then caption.""" doc.add_paragraph() # space before p_img = doc.add_paragraph() p_img.alignment = WD_ALIGN_PARAGRAPH.CENTER run = p_img.add_run() run.add_picture(img_path, width=Inches(width_inches)) p_cap = doc.add_paragraph(caption_text) p_cap.alignment = WD_ALIGN_PARAGRAPH.CENTER for run in p_cap.runs: run.font.size = Pt(9) run.font.italic = True run.font.color.rgb = RGBColor(0x59, 0x59, 0x59) doc.add_paragraph() # space after charts_to_add = [ (chart1, 'Figure 1: Pre vs Post Intervention Mean Scores (±SD) for TUG Test, Pressure Biofeedback, and PF-10 (n=25). All outcomes: p<0.001.', 6.2), (chart2, 'Figure 2: Mean Improvement (±SD) in TUG, PBF, and PF-10 Scores After 4-Week Hypopressive Exercise Program.', 5.8), (chart3, 'Figure 3: Pie Charts Showing Percentage Improvement in Each Outcome Measure After 4-Week Hypopressive Exercise Program.', 6.0), ] body_count_before = len(body) for img, cap, w in charts_to_add: add_figure_block(doc, img, cap, w) # Find 4.8 Summary heading target_elem = None for elem in body: tag = elem.tag.split('}')[-1] if '}' in elem.tag else elem.tag if tag == 'p': text = ''.join(r.text or '' for r in elem.iter(qn('w:t'))) if '4.8' in text and 'Summary' in text: target_elem = elem break print("Target found:", target_elem is not None) # Move new elements before section 4.8 new_elements = list(body)[body_count_before:] print(f"Moving {len(new_elements)} elements before section 4.8") for elem in new_elements: body.remove(elem) for elem in new_elements: target_elem.addprevious(elem) doc.save(out) print(f"Saved: {out}") EOF
aditi final result with charts
Word Document · DOCX