Page 1 of 1
Chat With Google Gemini - An Interactive Generative AI-Powered Web Chat
Posted: Tue Jan 30, 2024 8:05 pm
by Eli
Re: Google Gemini - An Interactive Generative AI-Powered Web Chat
Posted: Fri Feb 02, 2024 4:48 pm
by Eli
Me: Write a Python code to visualize simple bar charts.
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)
