heatmap.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import plotly_express as px
  2. import pandas as pd
  3. import plotly
  4. # Read data from excel
  5. df = pd.read_csv("../docs/keyword.csv")
  6. keyword = df['Keyword']
  7. # competition = df['Competition (indexed value)']
  8. bid = df['Top of page bid (low range)']
  9. search = df['Avg_monthly_searches']
  10. margin = df['Top of page bid (low range)']
  11. remark = df['Keyword']
  12. # Create chart and store as figure [fig]
  13. fig = px.treemap(df,
  14. path=[keyword, bid],
  15. values=search,
  16. color=margin,
  17. # color_continuous_scale=['green', 'yellow', 'red'],
  18. color_continuous_scale=px.colors.sequential.Peach,
  19. title='Keyword Overview',
  20. hover_name=remark,
  21. )
  22. fig.update_traces(root_color="lightgrey")
  23. # Update/change layout
  24. fig.update_layout(title_font_size=42,
  25. title_font_family='Arial',
  26. margin=dict(t=50, l=25, r=25, b=25)
  27. )
  28. fig.show()
  29. # save chart and export to HTML
  30. plotly.offline.plot(fig, filename='../chart.html')