123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- # #import some lib
- # import numpy as np # linear algebra
- # import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
- # import matplotlib.pyplot as plt
- # import seaborn as sns
- #
- # color = sns.color_palette()
- # # %matplotlib inline
- # pd.options.mode.chained_assignment = None# default='warn'
- # order_products_prior_df = pd.read_csv("../docs/keyword.csv")
- # # aisles_df = pd.read_csv("../input/aisles.csv")
- # # departments_df = pd.read_csv("../input/departments.csv")
- # # order_products_prior_df = pd.merge(products_df, aisles_df, on='aisle_id', how='left')
- # # order_products_prior_df = pd.merge(order_products_prior_df, departments_df, on='department_id', how='left')
- # order_products_prior_df.head()
- #
- # import matplotlib
- # import squarify
- #
- # temp = order_products_prior_df[['keyword','Avg_monthly_searches']]
- # temp = pd.concat([
- # order_products_prior_df.groupby('keyword')['Avg_monthly_searches'].nunique().rename('Avg_monthly_searches')
- # # order_products_prior_df.groupby('department')['aisle'].nunique().rename('aisle_department')
- # ], axis=1).reset_index()
- # temp = temp.set_index('keyword')
- # temp2 = temp.sort_values(by="Avg_monthly_searches", ascending=False)
- #
- # # TreeMap parameters
- # x = 0.
- # y = 0.
- # width = 100.
- # height = 100.
- # cmap = matplotlib.cm.viridis
- #
- # # color scale on the population
- # # min and max values without Pau
- # mini, maxi = temp2.products_department.min(), temp2.products_department.max()
- # norm = matplotlib.colors.Normalize(vmin=mini, vmax=maxi)
- # colors = [cmap(norm(value)) for value in temp2.products_department]
- # colors[1] = "#FBFCFE"
- #
- # # labels for squares
- # labels = ["%s/n%d search num keyword num" % (label)
- # for label in zip(temp2.index, temp2.Avg_monthly_searches)]
- #
- # # make plot
- # fig = plt.figure(figsize=(12, 10))
- # fig.suptitle("search keyword", fontsize=20)
- # ax = fig.add_subplot(111, aspect="equal")
- # ax = squarify.plot(temp2.Avg_monthly_searches, color=colors, label=labels, ax=ax, alpha=.7)
- # ax.set_xticks([])
- # ax.set_yticks([])
- # # color bar
- # # create dummy invisible image with a color map
- # img = plt.imshow([temp2.Avg_monthly_searches], cmap=cmap)
- # img.set_visible(False)
- # fig.colorbar(img, orientation="vertical", shrink=.96)
- # fig.text(.76, .9, "numbers of products", fontsize=14)
- # fig.text(.5, 0.1,
- # "powered by CJ /n keyword totale %d" % (temp2.Avg_monthly_searches.sum()), fontsize=14, ha="center")
- # fig.text(.5, 0.07,
- # "Source : http://netfly",
- # fontsize=14,
- # ha="center")
- # plt.show()
- import matplotlib.pyplot as plt
- plt.rcParams['font.sans-serif'] = ['Taipei Sans TC Beta']
- sales = [100, 80, 50]
- x_labels = ['A品牌', 'B品牌', 'C品牌']
- plt.bar(x_labels, sales)
- plt.show()
|