GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-data-visualization/Matplotlib/plot-wp-graph.py at main · javedali99/python-data-visualization Expand file tree/ Copy pathplot-wp-graph.pyMore file actions 108 lines (89 loc) · 3.68 KB / Copy pathplot-wp-graph.pyFile metadata and controls108 lines (89 loc) · 3.68 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 """ Visualization of Death Rate Gap Over Time Author: Javed Ali Date: October 22, 2023 Description: This script visualizes the growing gap in death rates between the wealthiest and poorest areas over a span of 40 years, from 1980 to 2020. The data is plotted on a 2D chart, highlighting key points with annotations. Key Components: - Data: Years (`1980, 2000, 2015, 2020`) and death rates for both wealthiest and poorest areas. - Visualization: - Filled region between two lines representing the difference in death rates. - Individual lines and markers for both death rates. - Annotations indicating the difference in death rates at specific points. - Dotted lines connecting the death rates to highlight the difference. - Styling: - Removal of top, right, and left spines for clarity. - Horizontal grid lines for better readability. - Custom x and y tick labels. - Title, subtitle, and footer information for comprehensive understanding. Sources: Data for this visualization is sourced from the "Centers for Disease Control and Prevention" and the "U.S. Census Bureau", as referenced in the footer of the plot. Usage: To visualize the data, simply run the script. The matplotlib library is utilized to generate the plot, which displays upon execution. """ # Import required libraries import matplotlib.pyplot as plt # Data years = [1980, 2000, 2015, 2020] death_rate_wealthiest = [600, 650, 675, 700] death_rate_poorest = [688, 847, 1002, 1148] fig, ax = plt.subplots(figsize=(10, 7)) # Plot lines and fill ax.fill_between(years, death_rate_wealthiest, death_rate_poorest, color="#E6E6FA") ax.plot(years, death_rate_wealthiest, color="#C0C0C0", lw=2, marker="o") ax.plot(years, death_rate_poorest, color="#8A2BE2", lw=2, marker="o") # Annotations for the death rates and dotted lines for y, w, p in zip(years, death_rate_wealthiest, death_rate_poorest): diff = p - w ax.text(y + 0.5, (w + p) / 2, f"{diff} more deaths", ha="center", va="center", fontsize=9, color="#8A2BE2") ax.plot([y, y], [w, p], linestyle="--", color="#8A2BE2", linewidth=0.5) # Additional texts ax.text(1983, 805, "Death rate in \npoorest areas", color="#8A2BE2", fontsize=9) ax.text(1985, 520, "Death rate in \nwealthiest areas", color="#C0C0C0", fontsize=9) ax.text( 1995, 900, "By 2000, the death rate gap\nhad grown so that people in the\npoorest areas were 27 percent\nmore likely to die each year.", fontsize=8, ha="left", color="#8A2BE2", ) ax.text( 2015, 1010, "By 2015, people in the poorest\nareas were 49 percent more likely\nto die each year.", fontsize=8, ha="right", color="#8A2BE2", ) # Styling ax.spines["top"].set_visible(False) ax.spines["right"].set_visible(False) ax.spines["left"].set_visible(False) ax.spines["bottom"].set_color("#C0C0C0") # Grid Lines ax.grid(axis="y", linestyle="--", linewidth=0.5, color="#C0C0C0") # Title and Subtitle ax.text(1978, 1392, "Small death gap has grown wide", fontsize=15, fontweight="bold", ha="left") ax.text( 1978, 1265, "In the early 1980s, people in the poorest areas were 9 percent more likely to\ndie each year, with 88 more deaths per 100,000 people than their wealthy\ncounterparts. That gap has widened significantly over time.", fontsize=10, ha="left", ) # Footer footer = "Source: Centers for Disease Control and Prevention, U.S. Census Bureau" ax.text(2000, -120, footer, fontsize=8, color="#C0C0C0") # Adjusting y-axis limits and labels ax.set_xlim(1978, 2022) ax.set_ylim(0, 1200) # Adjusting tick labels ax.set_xticks([1980, 2000, 2015, 2020]) ax.set_yticks(range(0, 1201, 200)) ax.set_yticklabels([str(i) if i != 1200 else "1200 deaths per 100K" for i in range(0, 1201, 200)]) plt.tight_layout() plt.show() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |