treemap7.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # #import some lib
  2. # import numpy as np # linear algebra
  3. # import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
  4. # import matplotlib.pyplot as plt
  5. # import seaborn as sns
  6. #
  7. # color = sns.color_palette()
  8. # # %matplotlib inline
  9. # pd.options.mode.chained_assignment = None# default='warn'
  10. # order_products_prior_df = pd.read_csv("../docs/keyword.csv")
  11. # # aisles_df = pd.read_csv("../input/aisles.csv")
  12. # # departments_df = pd.read_csv("../input/departments.csv")
  13. # # order_products_prior_df = pd.merge(products_df, aisles_df, on='aisle_id', how='left')
  14. # # order_products_prior_df = pd.merge(order_products_prior_df, departments_df, on='department_id', how='left')
  15. # order_products_prior_df.head()
  16. #
  17. # import matplotlib
  18. # import squarify
  19. #
  20. # temp = order_products_prior_df[['keyword','Avg_monthly_searches']]
  21. # temp = pd.concat([
  22. # order_products_prior_df.groupby('keyword')['Avg_monthly_searches'].nunique().rename('Avg_monthly_searches')
  23. # # order_products_prior_df.groupby('department')['aisle'].nunique().rename('aisle_department')
  24. # ], axis=1).reset_index()
  25. # temp = temp.set_index('keyword')
  26. # temp2 = temp.sort_values(by="Avg_monthly_searches", ascending=False)
  27. #
  28. # # TreeMap parameters
  29. # x = 0.
  30. # y = 0.
  31. # width = 100.
  32. # height = 100.
  33. # cmap = matplotlib.cm.viridis
  34. #
  35. # # color scale on the population
  36. # # min and max values without Pau
  37. # mini, maxi = temp2.products_department.min(), temp2.products_department.max()
  38. # norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)
  39. # colors = [cmap(norm(value)) for value in temp2.products_department]
  40. # colors[1] = "#FBFCFE"
  41. #
  42. # # labels for squares
  43. # labels = ["%s/n%d search num keyword num" % (label)
  44. # for label in zip(temp2.index, temp2.Avg_monthly_searches)]
  45. #
  46. # # make plot
  47. # fig = plt.figure(figsize=(12, 10))
  48. # fig.suptitle("search keyword", fontsize=20)
  49. # ax = fig.add_subplot(111, aspect="equal")
  50. # ax = squarify.plot(temp2.Avg_monthly_searches, color=colors, label=labels, ax=ax, alpha=.7)
  51. # ax.set_xticks([])
  52. # ax.set_yticks([])
  53. # # color bar
  54. # # create dummy invisible image with a color map
  55. # img = plt.imshow([temp2.Avg_monthly_searches], cmap=cmap)
  56. # img.set_visible(False)
  57. # fig.colorbar(img, orientation="vertical", shrink=.96)
  58. # fig.text(.76, .9, "numbers of products", fontsize=14)
  59. # fig.text(.5, 0.1,
  60. # "powered by CJ /n keyword totale %d" % (temp2.Avg_monthly_searches.sum()), fontsize=14, ha="center")
  61. # fig.text(.5, 0.07,
  62. # "Source : http://netfly",
  63. # fontsize=14,
  64. # ha="center")
  65. # plt.show()
  66. import matplotlib.pyplot as plt
  67. plt.rcParams['font.sans-serif'] = ['Taipei Sans TC Beta']
  68. sales = [100, 80, 50]
  69. x_labels = ['A品牌', 'B品牌', 'C品牌']
  70. plt.bar(x_labels, sales)
  71. plt.show()