def theme_plots(dark=False): plt.style.use('default') from qbstyles import mpl_style mpl_style(dark=dark) if dark: plt.rcParams['figure.facecolor'] = '#111111'
def main(): """Main.""" fp = DR / '2018.csv' df = pd.read_csv(str(fp)) mpl_style(dark=True) fig = plt.figure(figsize=(12, 6), dpi=72) # figsize * dpi ax = fig.add_subplot( 111, # 1行目1列の1番目 xlabel=df['GameID'].name, # ylabel='number' ) plt.ylabel('number', rotation=0, labelpad=30) fig.suptitle('Multi Bars') col_list = ['H', 'HR', 'K', 'BB'] w = 0.15 for i, col in enumerate(col_list): ax.bar(df.index + w * (i - len(col_list) / 2), df.loc[:, col], label=col, width=w, align='edge', zorder=10) ax.tick_params(bottom=False) ax.grid(axis='y', c='gainsboro', zorder=9) for side in ['right', 'top']: ax.spines[side].set_visible(False) ax.legend() fig.savefig(str(DR / 'bar.png')) plt.show()
def main(): mpl_style(dark=False) plt.style.use('./egta/experiments/style/style_heatmap.mplstyle') evaluation_data_folder_path = os.path.join(ROOT_DATA_FOLDER, 'regen_exp', 'tragedy', '') evaluation_data_save_file_name = 'evaluation_results_data.p' algorithms_list, regen_rates_list, seeds_list, n_episodes, max_n_steps, n_agents = load_meta_data( evaluation_data_folder_path, evaluation_data_save_file_name) actions = load_actions(evaluation_data_folder_path, evaluation_data_save_file_name) restraint_data = compute_average_restraint(actions, n_episodes, n_agents) plot_restraint_heat_map(restraint_data, ALGO_NAMES_ORDERD, evaluation_data_folder_path, None, letter="")
def render(df): dataDir = os.path.dirname(os.path.abspath(__file__)) + "/../../data/" dfGrowthDNM = pd.read_csv(dataDir + "darknetmarkets_growth.csv") dfGrowthDNMN = pd.read_csv(dataDir + "darknetmarketsnoobs_growth.csv") variants = [ ("/r/DarkNetMarkets", "pre-February 2015"), ("/r/DarkNetMarkets", "post-February 2015"), ("/r/DarkNetMarketsNoobs", "pre-February 2015"), ("/r/DarkNetMarketsNoobs", "post-February 2015") ] for (subreddit, period) in variants: if subreddit == "/r/DarkNetMarkets": dfRedditGrowth = dfGrowthDNM else: dfRedditGrowth = dfGrowthDNMN dfRedditGrowth['date'] = pd.to_datetime(dfRedditGrowth['date']) dfRevenue = df.groupby(['date'])['order_amount_usd'].sum().to_frame().reset_index() dfRevenue['date'] = pd.to_datetime(dfRevenue['date']) dfRevenue = dfRevenue.merge(dfRedditGrowth, on='date', how='inner') dfRevenue['growth'] = dfRevenue['growth'].rolling(7, center=True).mean() dfRevenue['order_amount_usd'] = dfRevenue['order_amount_usd'].rolling(7, center=True).mean() dfRevenue = dfRevenue.dropna() if period == "pre-February 2015": dfRevenue = dfRevenue[dfRevenue['date'] < pd.to_datetime('February 15 2015')] else: dfRevenue = dfRevenue[dfRevenue['date'] > pd.to_datetime('February 15 2015')] x = dfRevenue['order_amount_usd'].tolist() y = dfRevenue['growth'].tolist() corr, p_value = stats.kendalltau(x, y) from qbstyles import mpl_style mpl_style(dark=False) plt.figure(figsize=(10,6)) points = plt.scatter(dfRevenue['order_amount_usd'], dfRevenue['growth'], c=[date2num(i.date()) for i in dfRevenue.date], s=20, cmap="plasma") plt.colorbar(points, format=DateFormatter('%b %y')) ax = sns.regplot("order_amount_usd", "growth", data=dfRevenue, scatter=False) #ax.set(xlabel='Daily Revenue in USD', ylabel='Daily Growth in Users', title='Subscriber Growth of {} vs. Revenue ({})'.format(subreddit, period)) plt.ylim(bottom=-1) ax.text(max(x) * 0.8, max(y) * 0.95, r'$\tau$=' + str(round(corr, 2)) + '\np-value= ' + str(round(p_value, 2))) plt.show()
def main(): """Main.""" fp = DR / '2018.csv' df = pd.read_csv(str(fp)) mpl_style(dark=True) fig = plt.figure(figsize=(10, 8), dpi=72) # figsize * dpi ax = fig.add_subplot(111, xlabel=df['GameID'].name, ylabel='number') ax.plot(df['H']) ax.plot(df['HR'], 'rs:', label='HR', ms=10, mew=5, mec='green') ax.plot(df['K'], marker='^', linestyle='-.') fig.savefig(str(DR / 'plot.png')) plt.show()
def __init__(self, params): MWB.__init__(self, params) QWidget.__init__(self) self.setStyleSheet(''' background-color: transparent; ''') mpl_style(dark=True) self.setLayout(QVBoxLayout()) self.canvas = FigureCanvas(Figure(figsize=(5, 3))) self.layout().addWidget(self.canvas) self.setFixedWidth(550) self.setFixedHeight(500) self.ax = self.canvas.figure.subplots()
def main(): '''Main.''' mpl_style(dark=True) fig = plt.figure() ims = [] for i in range(10): rand = np.random.randn(100) # 100個の乱数を生成 im = plt.plot(rand) # 乱数をグラフにする ims.append(im) # グラフを配列 ims に追加 # 10枚のプロットを 100ms ごとに表示 # aniは絶対要る ani = animation.ArtistAnimation(fig, ims, interval=100) ani.save(str(DR / 'anime.gif'), writer='pillow') plt.show()
def main(): """Main.""" # Create a random (normal distribution) dataset observation_count = 1000 series_count = 5 random_data = np.random.randn(observation_count, series_count) # print(random_data) bucket_count = 10 mpl_style(dark=False) fig = plt.figure(figsize=(14, 6), dpi=72) fig.suptitle('Hist Random') # Use default styling plt.hist(random_data, bucket_count) fig.savefig(str(DR / 'hist_rand.png')) plt.show()
def main(): '''Main.''' mpl_style(dark=False) fig = plt.figure() x = np.arange(0, 10, 0.1) ims = [] for a in range(50): y = np.sin(x - a) line, = plt.plot(x, y, 'r') ims.append([line]) ani = animation.ArtistAnimation(fig, ims) ani.save(str(DR / 'anime_sin.gif'), writer='pillow') # ani.save( # 'anime_sin.mp4', # writer='ffmpeg' # ) plt.show()
def main(): mpl_style(dark=False) plt.style.use('./egta/experiments/style/style.mplstyle') results_data_folder_path = os.path.join(ROOT_DATA_FOLDER, 'regen_exp', '') interactions_save_file_name = 'interaction_results_data.p' rewards = load_rewards(results_data_folder_path, interactions_save_file_name) cooperators_ids = load_cooperator_ids(results_data_folder_path, interactions_save_file_name) transformed_data = transform_data(rewards, cooperators_ids) xlim, ylim = calculate_global_xlim_and_ylim(transformed_data, ALGO_NAMES_ORDERD) xlim *= 1.1 plot_results_with_nsi_inset(transformed_data=transformed_data, algo_names=ALGO_NAMES_ORDERD, xlim=xlim, folder_path=results_data_folder_path)
def main(): """Main.""" fp = DR / '2018.csv' data = pd.read_csv(str(fp)) mpl_style(dark=True) fig = plt.figure(figsize=(8, 4), dpi=72) # figsize * dpi ax = fig.add_subplot( 111, # 1行目1列の1番目 xticks=range(0, 20, 2)) n, bins, patches = ax.hist(data['R'], bins=data['R'].max() - data['R'].min()) fig.suptitle('Hist') for i in range(len(bins) - 1): ax.text((bins[i + 1] + bins[i]) / 2, n[i], int(n[i]), horizontalalignment='center') fig.savefig(str(DR / 'hist.png')) plt.show()
from argparse import ArgumentParser from os import path import pandas as pd from sklearn.linear_model import LinearRegression import numpy as np import matplotlib.pyplot as plt from scipy.stats import kendalltau import seaborn as sns from qbstyles import mpl_style from scipy.stats import kendalltau, zscore, shapiro mpl_style(dark=False) class MediaCoverageCategories: @staticmethod def render(df, next=False): mapping = { 'other - fake': 'other', 'other - guide': 'other', 'other - account': 'other', 'other - custom': 'other', 'other - pirated software': 'other', 'other - voucher/invite/codes/lottery/gift': 'other', 'RAT': 'hacking services & tools', 'exploits': 'hacking services & tools', 'botnet': 'hacking services & tools', 'e-mail': 'hacking services & tools', 'malware': 'hacking services & tools', 'website': 'development', 'app': 'development', 'hosting': 'development',