Chat With Google Gemini - An Interactive Generative AI-Powered Web Chat

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

Me: Write a Python code to visualize simple bar charts.

Gemini:

  1. import matplotlib.pyplot as plt
  2. import pandas as pd
  3.  
  4. # Create a dataframe
  5. data = pd.DataFrame({
  6.     'Country': ['USA', 'China', 'India', 'Japan', 'Germany'],
  7.     'Population': [331000000, 1426000000, 1380000000, 126000000, 83000000]
  8. })
  9.  
  10. # Create a bar chart
  11. plt.bar(data['Country'], data['Population'])
  12.  
  13. # Add axis labels
  14. plt.xlabel('Country')
  15. plt.ylabel('Population (millions)')
  16.  
  17. # Add a title
  18. plt.title('Population of the Top 5 Countries')
  19.  
  20. # Display the plot
  21. plt.show()
  22.  
  23. # Customization
  24. # Change the color of the bars
  25. plt.bar(data['Country'], data['Population'], color='blue')
  26.  
  27. # Add a legend
  28. plt.legend(['Population'])
  29.  
  30. # Change the size of the plot
  31. plt.figure(figsize=(10, 5))
  32.  
  33. # Add grid lines
  34. plt.grid(True)
  35.  
  36. # Horizontal bar chart
  37. plt.barh(data['Country'], data['Population'])
  38.  
  39. # Add axis labels
  40. plt.ylabel('Country')
  41. plt.xlabel('Population (millions)')
  42.  
  43. # Display the plot
  44. plt.show()
  45.  
  46. # Customization
  47. # Change the color of the bars
  48. plt.barh(data['Country'], data['Population'], color='green')
  49.  
  50. # Add a legend
  51. plt.legend(['Population'])
  52.  
  53. # Change the size of the plot
  54. plt.figure(figsize=(5, 10))
  55.  
  56. # Add grid lines
  57. plt.grid(True)

Image

Image
Attachments
bar2.png
bar1.png
(19.59 KiB) Not downloaded yet
bar1.png
(19.59 KiB) Not downloaded yet
0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply

Return to “Technologies for Teaching, Learning, Research, Problem Solving and Business”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests