Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import plotly.plotly as py
- from plotly.graph_objs import *
- import pandas as pd
- def main():
- #Read data from spreadsheet in
- fileName = 'Technical Report Survey (Responses).xlsx'
- excel = pd.ExcelFile(fileName)
- sheet = excel.parse('Form Responses 1')
- #Generate The First Pie Chart
- MultiPie(sheet, sheet.Know, 'Percent of College Students Who Can Confidently Write A Technical Report.')
- #Generate the next one
- MultiPie(sheet, sheet.Heard, 'Percent of College Students Who Know What A Technical Report Is.')
- def MultiPie(df, checkC, chart_name):
- labels = ['Yes','No']
- colors = ['#13d100','#da2700']
- sValues = [
- df[(checkC == 'Yes') & (df.Major == 'STEM')].count()[0],
- df[(checkC == 'No') & (df.Major == 'STEM')].count()[0]
- ]
- bValues = [
- df[(checkC == 'Yes') & (df.Major == 'Business')].count()[0],
- df[(checkC == 'No') & (df.Major == 'Business')].count()[0]
- ]
- pValues = [
- df[(checkC == 'Yes') & (df.Major == 'Pilot')].count()[0],
- df[(checkC == 'No') & (df.Major == 'Pilot')].count()[0]
- ]
- oValues = [
- df[(checkC == 'Yes') & (df.Major == 'Other')].count()[0],
- df[(checkC == 'No') & (df.Major == 'Other')].count()[0]
- ]
- fig = {
- 'data': [
- #STEM
- {
- 'labels': labels,
- 'values': sValues,
- 'marker': {'colors': colors},
- 'type': 'pie',
- 'name': 'STEM',
- 'domain': {'x': [0, .5],
- 'y': [.55, .9]},
- 'hoverinfo':'label+percent+value',
- 'textinfo':'none',
- },
- #Business
- {
- 'labels': labels,
- 'values': bValues,
- 'type': 'pie',
- 'name': 'Business',
- 'marker': {'colors': colors},
- 'domain': {'x': [.5, .9],
- 'y': [.55, .9]},
- 'hoverinfo':'label+percent+value',
- 'textinfo':'none',
- },
- #Pilot
- {
- 'labels': labels,
- 'values': pValues,
- 'marker': {'colors': colors},
- 'type': 'pie',
- 'name': 'Pilot',
- 'domain': {'x': [0, .5],
- 'y': [.1, .45]},
- 'hoverinfo':'label+percent+value',
- 'textinfo':'none',
- },
- #Other
- {
- 'labels': labels,
- 'values': oValues,
- 'marker': {'colors': colors},
- 'type': 'pie',
- 'name':'Other',
- 'domain': {'x': [.5, .9],
- 'y': [.1, .45]},
- 'hoverinfo':'label+percent+value',
- 'textinfo':'none',
- }
- ],
- 'layout': {
- 'title': chart_name,
- 'showlegend': False,
- "annotations": [
- {
- "font": {
- "size": 20
- },
- "showarrow": False,
- "text": "STEM",
- "x": 0.22,
- "y": 1
- },
- {
- "font": {
- "size": 20
- },
- "showarrow": False,
- "text": "Business",
- "x": 0.73,
- "y": 1
- },
- {
- "font": {
- "size": 20
- },
- "showarrow": False,
- "text": "Pilot",
- "x": 0.20,
- "y": 0.5
- },
- {
- "font": {
- "size": 20
- },
- "showarrow": False,
- "text": "Other",
- "x": 0.74,
- "y": 0.5
- }
- ]
- }
- }
- #and finally plot everything!
- py.iplot(fig, filename=chart_name)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement