Reputation: 166
I have an Excel sheet shared here: https://docs.google.com/spreadsheets/d/1WolE-TpyEXtv1rlr3xusESke46UMlRurAEH1D1Lsyss/edit?usp=sharing
I am trying to create work progress graph and here is my code:
import datetime
from datetime import date
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
df = pd.read_excel('Test Execution Progress.xlsx')
dp = df.groupby(by=['Project ID', 'Release Name', 'Cycle Name'],
as_index=False).plot(x=['Test Execution Date'],
y=['Planned', 'Commulative Tested', 'Commulative Passed'],
figsize=(16, 6), linestyle='dashed',marker='D', markersize=5,
title='Trest Exection Progress', legend=True, colormap='jet')
The target is to:
Help in this regard is highly appreciated.
Edit I found an example from here: enter link description here
And after making some changes, I managed to almost get what I wanted as follows:
Now, I just need to:
Upvotes: 1
Views: 3178
Reputation: 166
Finally, I resolved all issues and managed to get an desired output. Here is the code:
grouped = dfm.groupby(by=['Project ID', 'Release Name', 'Cycle Name'], as_index=False)
# Calculate the height of table to be displayed above the Testing Progress charts
l = len(dfp['Cycle Name']) + 2
# Create a row_num variable for locating the charts in Excel sheet
row_num = l
# Create a for loop to create charts grouped
for name, group in grouped:
image_data = BytesIO()
fig = plt.figure(figsize=(12, 4), dpi=None, facecolor='white')
ax1 = fig.add_subplot(111, facecolor='aliceblue')
group.plot.line(ax=ax1, color='purple', x='Test Execution Date',
y='Planned', linestyle='dashdot', marker='o', markersize=5)
ax1.set_ylabel('Test Cases Count')
ax2 = ax1.twinx()
group.plot.line(ax=ax1,color='blue',x='Test Execution Date',
y='Commulative Tested', linestyle='dotted', marker='o', markersize=5)
# ax2.set_ylabel('Test Cases Count')
group.plot.line(ax=ax1, color='green', x='Test Execution Date',
y='Commulative Passed', linestyle='dashed' ,marker='o',markersize=5)
fig.suptitle('Overall Release Progress', fontsize=12, fontweight='bold', x=0.5, y =1.01)
plt.title(' => '.join([str(i) for i in name]), fontsize=10, loc='center')
ax1.grid(b=True, which='major', color='grey', linestyle='dotted')
plt.yticks([])
ax1.invert_yaxis()
fig.savefig( image_data, format="png", dpi=100, facecolor='aliceblue', bbox_inches='tight', pad_inches=0.4)
worksheet1.insert_image('A' + str(row_num), "", {'image_data': image_data})
row_num += 23
# Rearrange the sheets
sheet_names = ['Test Execution Progress', 'Test Execution by Date']
workbook.worksheets_objs.sort(key=lambda x: sheet_names.index(x.name))
# Save the workbook
writer.save()
Here is the output:
Note: Names of the Project, Release Name and Cycle Names masked.
Upvotes: 2