Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pie Charts Escape Characters Format Strings © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

Similar presentations


Presentation on theme: "Pie Charts Escape Characters Format Strings © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering."— Presentation transcript:

1 Pie Charts Escape Characters Format Strings © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering

2 Pie Charts

3 The full circle must represent 100% of the quantity. Two variables are needed to make a pie chart: the labels of the categories the quantity in each category Pie Charts

4 Title the graphic Indicate the meaning of 100% Values labeled on sectors Total value of pie n=80 if a survey of 80 people Label the categories Optionally, label percents Pie Charts

5 Geometry Vocabulary radiuscentral anglearc sectorsegmentchord

6 Length Area Geometry Calculations θ θ rrr r r r

7 Relative Area Electricity generation by source and state in 2010 Coal Natural Gas Nuclear Hydroelectric Solar/Wind/Geothermal Biomass Petroleum Other

8 Beware: doubling the radius will increase area by factor of 4 Comparing Two Circles 3 3 6 6

9 # 2012 Consumer expenditures # http://www.bls.gov/news.release/cesan.nr0.htm quantities = [6599, 1913, 16887, 1736, 8998, 3556, 2605, 5591, 3557] labels=["Food", "Contributions to children\noutside the home", "Housing ", "Clothing\nand services", "Transit", "Health", "Entertainment", "Pensions","Other"] colors = ['pink', 'red', 'green', 'cyan', 'gray', 'white', 'yellow', 'lime', 'brown'] fig, ax = plt.subplots(1, 1) ax.pie(quantities, labels=labels, colors=colors, autopct='%.0f%') ax.set_aspect(1) # Square axes for round plot ax.set_title('2012 Mean Family Expenditures\n$52,442/year') fig.show() AxesSubplot.pie()

10 # 2012 Consumer expenditures # http://www.bls.gov/news.release/cesan.nr0.htm quantities = [6599,1913, 16887, 1736, 8998, 3556, 2605, 5591, 3557] labels=["Food", "Contributions to children\noutside the home", "Housing ", "Clothing\nand services", "Transit", "Health", "Entertainment", "Pensions","Other"] Colors = ['pink', 'red', 'green', 'cyan', 'gray', 'white', 'yellow', 'lime', 'brown'] fig, ax = plt.subplots(1, 1) ax.pie(quantities, labels=labels, colors=colors, autopct='%.0f%') ax.set_aspect(1) # Square axes for round plot ax.set_title('2012 Mean Family Expenditures\n$52,442/year') fig.show() Escape Characters

11 Use to include special characters in a string. CharacterEscape Sequence Newline \n Tab \t To escape the delimiter characters \' \" To escape the escape character \\ Escape Characters

12 # 2012 Consumer expenditures # http://www.bls.gov/news.release/cesan.nr0.htm quantities = [6599,1913, 16887, 1736, 8998, 3556, 2605, 5591, 3557] labels=["Food", "Contributions to children\noutside the home", "Housing ", "Clothing\nand services", "Transit", "Health", "Entertainment", "Pensions","Other"] Colors = ['pink', 'red', 'green', 'cyan', 'gray', 'white', 'yellow', 'lime', 'brown'] fig, ax = plt.subplots(1, 1) ax.pie(quantities, labels=labels, colors=colors, autopct='%.0f%') ax.set_aspect(1) # Square axes for round plot ax.set_title('2012 Mean Family Expenditures\n$52,442/year') fig.show() Escape Characters

13 # 2012 Consumer expenditures # http://www.bls.gov/news.release/cesan.nr0.htm quantities = [6599,1913, 16887, 1736, 8998, 3556, 2605, 5591, 3557] labels=["Food", "Contributions to children\noutside the home", "Housing ", "Clothing\nand services", "Transit", "Health", "Entertainment", "Pensions","Other"] Colors = ['pink', 'red', 'green', 'cyan', 'gray', 'white', 'yellow', 'lime', 'brown'] fig, ax = plt.subplots(1, 1) ax.pie(quantities, labels=labels, colors=colors, autopct='%.0f%') ax.set_aspect(1) # Square axes for round plot ax.set_title('2012 Mean Family Expenditures\n$52,442/year') fig.show() Format Strings

14 Format Strings specify how to print quantities '%. ' % indicates a quantity %i integer %e scientific notation %f decimal float = minimum #of characters = number of digits after the decimal point Format Strings

15 Examples of '%. ' Format Strings CodeOutput using 45.793 autopct='%f'45.793 autopct='%.1f'45.8 autopct='%.2f'45.79 autopct='%7.2f' 45.79 autopct='p=%.1f%'p=45.8%

16 Pie Charts

17 # California Energy Commission. (2014). Energy Losses in a Vehicle. quantities = [2.2, 5.6, 2.6, 4.2, 5.8, 62.4, 17.2] labels = ["Accessories", "Drivetrain Losses", "Aerodynamic Drag", "Rolling Resistance", "Overcoming Inertia", "Engine Losses", "Idling Losses"] colors = ['pink', 'red', 'w', 'cyan', '#00FF00', 'gray', 'brown'] fig, ax = plt.subplots(1, 1) ax.pie(quantities, labels=labels, colors=colors, autopct='%i%', explode=[0,0,0, 0,0.3,0, 0]) ax.set_aspect(1) # Square axes for round plot title = ax.set_title('Energy Losses in a Vehicle in City Driving') title.set_y(1.05) ax.text(0.7, -1.3, ' Source:\nCalifornia Energy Center') fig.show() AxesSubplot.pie()


Download ppt "Pie Charts Escape Characters Format Strings © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering."

Similar presentations


Ads by Google