tabnation

python map scale

Aug 8th, 2025
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import plotly.express as px
  2. import pandas as pd
  3.  
  4. # Collect user inputs
  5. countries = []
  6. values = []
  7.  
  8. print("Enter country names and values (1–100). Type 'done' when finished.\n")
  9.  
  10. while True:
  11. country = input("Enter country name (or 'done'): ").strip()
  12. if country.lower() == 'done':
  13. break
  14.  
  15. try:
  16. value = float(input(f"Enter value for {country} (1–100): ").strip())
  17. if 1 <= value <= 100:
  18. countries.append(country)
  19. values.append(value)
  20. else:
  21. print("Value must be between 1 and 100.")
  22. except ValueError:
  23. print("Please enter a valid number.")
  24.  
  25. # Create DataFrame
  26. data = pd.DataFrame({
  27. 'Country': countries,
  28. 'Values': values
  29. })
  30.  
  31. # Plot
  32. fig = px.choropleth(
  33. data,
  34. locations='Country',
  35. locationmode='country names',
  36. color='Values',
  37. color_continuous_scale='Inferno',
  38. title='how hot was it today'
  39. )
  40. fig.show()
  41.  
Advertisement
Add Comment
Please, Sign In to add comment