Gemini:
- import matplotlib.pyplot as plt
- import pandas as pd
- # Create a dataframe
- data = pd.DataFrame({
- 'Country': ['USA', 'China', 'India', 'Japan', 'Germany'],
- 'Population': [331000000, 1426000000, 1380000000, 126000000, 83000000]
- })
- # Create a bar chart
- plt.bar(data['Country'], data['Population'])
- # Add axis labels
- plt.xlabel('Country')
- plt.ylabel('Population (millions)')
- # Add a title
- plt.title('Population of the Top 5 Countries')
- # Display the plot
- plt.show()
- # Customization
- # Change the color of the bars
- plt.bar(data['Country'], data['Population'], color='blue')
- # Add a legend
- plt.legend(['Population'])
- # Change the size of the plot
- plt.figure(figsize=(10, 5))
- # Add grid lines
- plt.grid(True)
- # Horizontal bar chart
- plt.barh(data['Country'], data['Population'])
- # Add axis labels
- plt.ylabel('Country')
- plt.xlabel('Population (millions)')
- # Display the plot
- plt.show()
- # Customization
- # Change the color of the bars
- plt.barh(data['Country'], data['Population'], color='green')
- # Add a legend
- plt.legend(['Population'])
- # Change the size of the plot
- plt.figure(figsize=(5, 10))
- # Add grid lines
- plt.grid(True)