fork download
  1. import matplotlib.pyplot as plt
  2.  
  3. # Define the cities and their coordinates (latitude, longitude)
  4. cities = {
  5. "Delhi": (28.6139, 77.2090),
  6. "Mumbai": (19.0760, 72.8777),
  7. "Bangalore": (12.9716, 77.5946)
  8. }
  9.  
  10. # Create a 2-D flat map (cylindrical projection)
  11. plt.figure(figsize=(10, 5))
  12.  
  13. # Plot the cities on the map
  14. for city, (lat, lon) in cities.items():
  15. plt.scatter(lon, lat, color='red', s=100, label=city)
  16. plt.text(lon + 1, lat, city, fontsize=12, color='black')
  17.  
  18. # Add gridlines
  19. plt.grid(True, linestyle='--', alpha=0.7)
  20.  
  21. # Set map limits (focus on India)
  22. plt.xlim(65, 100) # Longitude range
  23. plt.ylim(5, 35) # Latitude range
  24.  
  25. # Add labels and title
  26. plt.xlabel("Longitude")
  27. plt.ylabel("Latitude")
  28. plt.title("Location of Major Indian Cities on a 2-D Map")
  29.  
  30. # Add a legend
  31. plt.legend(loc="upper right")
  32.  
  33. # Show the plot
  34. plt.show()
Success #stdin #stdout #stderr 3.44s 68076KB
stdin
import matplotlib.pyplot as plt

# Define the cities and their coordinates (latitude, longitude)
cities = {
    "Delhi": (28.6139, 77.2090),
    "Mumbai": (19.0760, 72.8777),
    "Bangalore": (12.9716, 77.5946)
}

# Create a 2-D flat map (cylindrical projection)
plt.figure(figsize=(10, 5))

# Plot the cities on the map
for city, (lat, lon) in cities.items():
    plt.scatter(lon, lat, color='red', s=100, label=city)
    plt.text(lon + 1, lat, city, fontsize=12, color='black')

# Add gridlines
plt.grid(True, linestyle='--', alpha=0.7)

# Set map limits (focus on India)
plt.xlim(65, 100)  # Longitude range
plt.ylim(5, 35)    # Latitude range

# Add labels and title
plt.xlabel("Longitude")
plt.ylabel("Latitude")
plt.title("Location of Major Indian Cities on a 2-D Map")

# Add a legend
plt.legend(loc="upper right")

# Show the plot
plt.show()
stdout
Standard output is empty
stderr
Fontconfig error: No writable cache directories