{
  "countries": [
    {
      "country": "Afghanistan",
      "Sunni_Percentage": 85,
      "Shia_Percentage": 15
    },
    {
      "country": "Bahrain",
      "Sunni_Percentage": 30,
      "Shia_Percentage": 70
    },
    {
      "country": "Iran",
      "Sunni_Percentage": 10,
      "Shia_Percentage": 90
    },
    {
      "country": "Iraq",
      "Sunni_Percentage": 30,
      "Shia_Percentage": 70
    },
    {
      "country": "Lebanon",
      "Sunni_Percentage": 30,
      "Shia_Percentage": 30,
      "Christian_Percentage": 40
    },
    {
      "country": "Pakistan",
      "Sunni_Percentage": 75,
      "Shia_Percentage": 20,
      "Other_Percentage": 5
    },
    {
      "country": "Saudi Arabia",
      "Sunni_Percentage": 85,
      "Shia_Percentage": 15
    },
    {
      "country": "Syria",
      "Sunni_Percentage": 74,
      "Shia_Percentage": 13,
      "Other_Percentage": 13
    },
    {
      "country": "Turkey",
      "Sunni_Percentage": 80,
      "Shia_Percentage": 20
    },
    {
      "country": "Yemen",
      "Sunni_Percentage": 55,
      "Shia_Percentage": 45
    }
  ]
}
import matplotlib.pyplot as plt
import seaborn as sns
from io import BytesIO
from PIL import Image
import pandas as pd

def generate_plot(data):
    # Convert the JSON data to a Pandas DataFrame
    df = pd.json_normalize(data, 'countries')

    # Set the seaborn style
    sns.set(style="darkgrid")

    # Define stacked bar plot
    colors = sns.color_palette("muted")

    # Separating populations
    plot_data = df.melt(id_vars=["country"], value_vars=["Sunni_Percentage", "Shia_Percentage", 
                                                         "Christian_Percentage", "Other_Percentage"],
                        var_name='Population',
                        value_name='Percentage').fillna(0)

    # Initialize the matplotlib figure
    f, ax = plt.subplots(figsize=(10, 8))

    # Create the stacked bar chart
    sns.barplot(x="Percentage", y="country", hue="Population", data=plot_data,
                palette=colors, edgecolor="w")

    # Add legend, title and axis labels
    ax.set(title="Sunni and Shia Muslim Population Ratios by Country",
           xlabel="Percentage", ylabel="Country")
    ax.legend(loc='best', title="Population Groups")

    # Save plot to a BytesIO object
    bytes_image = BytesIO()
    plt.savefig(bytes_image, format='png')
    bytes_image.seek(0)

    # Convert BytesIO to PIL Image and return it
    return Image.open(bytes_image)
The figure titled "Sunni and Shia Muslim Population Ratios by Country" presents a stacked bar chart that illustrates the proportions of Sunni and Shia Muslim populations across ten countries in the Middle East and South Asia. Each bar represents a country and the colors denote different population groups, primarily Sunni and Shia Muslims.

The data for Afghanistan, Bahrain, Iran, Iraq, Lebanon, Pakistan, Saudi Arabia, Syria, Turkey, and Yemen is depicted. For some countries, the chart also includes additional population categories such as Christians and Others where applicable.

In Afghanistan and Saudi Arabia, the majority of the population is Sunni Muslims, accounting for 85% in both countries, with the remaining 15% being Shia Muslims. This indicates a strong predominance of Sunnis in these countries.

Bahrain and Iraq have a reverse trend, with Shia Muslims constituting 70% of the population in both countries and Sunni Muslims comprising the remaining 30%. This shows that Shia Muslims are the dominant group in these countries.

Iran has the highest proportion of Shia Muslims at 90%, leaving only 10% for Sunni Muslims. This is the highest Shia majority among the countries represented in the chart.

Lebanon is unique as it shows a more diverse religious composition with 30% Sunni, 30% Shia, and 40% Christians. This highlights Lebanon’s significant Christian population alongside its two major Muslim sects.

Pakistan shows a substantial Sunni majority with 75% Sunnis, while Shia Muslims make up 20% of the population and others account for 5%.

Syria’s population is composed of 74% Sunni Muslims, 13% Shia Muslims, and another 13% categorized under other groups, indicating a significant presence of non-Muslim or other minority sects.

Turkey and Yemen reveal a different distribution; Turkey has 80% Sunni and 20% Shia Muslims, while Yemen presents a closer balance between the two groups with 55% Sunnis and 45% Shias.

Overall, the chart indicates a trend of Sunni dominance in most countries except for Iran, Bahrain, and Iraq where Shia Muslims form the majority. Lebanon stands out due to its significant Christian population. The presence of 'Other' and Christian categories in a few countries showcases the diverse religious landscape in the region.
[
    {
        "question": "Which country has the highest percentage of Sunni Muslims?",
        "answer": "Afghanistan and Saudi Arabia",
        "explanation": "Both Afghanistan and Saudi Arabia have the highest percentage of Sunni Muslims at 85%."
    },
    {
        "question": "Which country has the highest percentage of Shia Muslims?",
        "answer": "Iran",
        "explanation": "Iran has the highest percentage of Shia Muslims at 90%."
    },
    {
        "question": "Which countries have the same Sunni and Shia Muslim population ratios?",
        "answer": "Bahrain and Iraq",
        "explanation": "Both Bahrain and Iraq have 30% Sunni and 70% Shia Muslim populations."
    },
    {
        "question": "Which country has the most diverse religious composition shown in the figure?",
        "answer": "Lebanon",
        "explanation": "Lebanon has Sunni, Shia, and Christian populations. The Christian population is 40%, while both Sunni and Shia populations are 30% each."
    },
    {
        "question": "What is the percentage of other religious groups in Pakistan?",
        "answer": "5%",
        "explanation": "Pakistan has 5% of other religious groups apart from Sunni and Shia Muslims."
    },
    {
        "question": "Which country shows an equal percentage of Sunni and Shia Muslims?",
        "answer": "None",
        "explanation": "No country in the dataset shows an equal percentage of Sunni and Shia Muslims."
    },
    {
        "question": "How does the Sunni percentage in Saudi Arabia compare to that in Yemen?",
        "answer": "Saudi Arabia has a higher Sunni percentage than Yemen.",
        "explanation": "Saudi Arabia has 85% Sunni Muslims, whereas Yemen has 55% Sunni Muslims."
    },
    {
        "question": "Which country has the closest ratio of Sunni to Shia Muslims?",
        "answer": "Yemen",
        "explanation": "Yemen has the closest ratio with 55% Sunni and 45% Shia Muslims."
    },
    {
        "question": "In which country is the Shia Muslim population the smallest in percentage terms?",
        "answer": "Syria",
        "explanation": "Syria has the smallest Shia Muslim population percentage at 13%."
    },
    {
        "question": "Which country has the lowest Sunni Muslim population percentage?",
        "answer": "Iran",
        "explanation": "Iran has the lowest Sunni Muslim population percentage at 10%."
    }
]