def make_ax_profit_quantity(pd_profit, pd_quantity_sold, a_marker, a_color, num_timesteps, num_sellers, fontsize=20, ax=None): color = a_color[0] pd_data = pd_profit for i in range(num_sellers): ax.plot(range(len(pd_data)), pd_data[i], '-', marker=a_marker[i], markerfacecolor='none', color=color, label = 'Firm %d'%(i+1)) ax.set_xlim(0, num_timesteps) ax.set_xticks(np.arange(0, num_timesteps+1)) customaxis(ax = ax, position = 'left', color = color, label = 'Profit', scale = 'linear', size = fontsize, full_nrs = False, location = 0.0) ax.get_xaxis().set_major_formatter(tk.FuncFormatter(lambda x, p: format(int(x),','))) ax.legend() leg = ax.get_legend() (leg.legendHandles[i].set_color('black') for i in range(num_sellers)) # FIXME: title #ax.set_title("Firm 1's initial cost is 99\% of Firm 2's".format(gamma), fontsize=fontsize +5)
def ax_bars_from_data(a_price, a_cost, a_quantity_sold, a_profit, a_color, ax=None): # Setup if ax is None: _, ax = plt.subplots() num_sellers = len(a_price) a_color_alt = sb.color_palette("deep", num_sellers) a_xvalues = np.arange(1, num_sellers + 1) w = 0.2 # plot the price for each buyer ax.set_title( 'Firm 1\'s cost is {}\% of firm 2\'s and makes {}\% more profit'. format(a_cost[0], int(round(a_profit[0] / a_profit[1] - 1, 2) * 100))) color = a_color[0] ax.bar(a_xvalues - w, a_price, width=.8 * w, color=color, alpha=1.0, align='center') ax.bar(a_xvalues - w, a_cost, width=.8 * w, color='black', alpha=0.2, align='center') ax.set_xlabel('') ax.set_xticks(a_xvalues) ax.set_xticklabels(['Firm %d' % i for i in a_xvalues]) [ t.set_color(i) for (i, t) in zip(a_color_alt[0:num_sellers], ax.xaxis.get_ticklabels()) ] customaxis(ax=ax, position='left', color=color, label='Prices', scale='linear', size=fontsize, full_nrs=False, location=0.0) # plot the quantity for each seller, on same x axis as price plot, but on separate y axis axt = ax.twinx() color = a_color[1] axt.grid(False) axt.bar(a_xvalues, a_quantity_sold, width=.8 * w, color=color, align='center') axt.set_xticks(a_xvalues) axt.set_ylabel('Quantities', color=color, fontsize=fontsize) customaxis(ax=axt, position='right', color=color, label='Quantities', scale='linear', size=fontsize, full_nrs=False, location=1.0) # plot the profit for each seller axt2 = ax.twinx() color = a_color[2] axt2.grid(False) axt2.bar(a_xvalues + w, a_profit, width=.8 * w, color=color, align='center') axt2.set_xticks(a_xvalues) axt2.set_ylabel('Profit', color=color, fontsize=fontsize) axt2.autoscale(tight=True) customaxis(ax=axt2, position='right', color=color, label='Profit', scale='linear', size=fontsize, full_nrs=False, location=1.12) ax.set_xlim([min(a_xvalues) - 1.5 * w, max(a_xvalues) + 1.5 * w])
def make_ax_profit_quantity_share(pd_profit, pd_quantity_sold, a_marker, a_color, num_sellers, gamma, fontsize=20, x_ticks=None, ax=None): # FIXME: x_ticks color = a_color[0] pd_data = pd_profit.div(pd_profit.sum(1), 0) print('HIHIHI') print(pd_profit) print(pd_data) if x_ticks is None: x_ticks = range(len(pd_data)) x_ticks = np.round(x_ticks, 2) for i in range(num_sellers): ax.plot(x_ticks, pd_data[i], '-', marker=a_marker[i], markerfacecolor='none', color=color, label='Firm %d' % (i + 1)) ax.set_xlim(min(x_ticks), max(x_ticks)) ax.set_xticks(x_ticks) customaxis(ax=ax, position='left', color=color, label='Profit Share', scale='linear', size=fontsize, full_nrs=False, location=0.0) ax.get_xaxis().set_major_formatter( tk.FuncFormatter(lambda x, p: format(x, ','))) ax.legend() leg = ax.get_legend() (leg.legendHandles[i].set_color('black') for i in range(num_sellers)) # Quantity axt = ax.twinx() color = a_color[1] pd_data = pd_quantity_sold.div(pd_quantity_sold.sum(1), 0) print('BYBYBY') print(pd_quantity_sold) print(pd_data) for i in range(num_sellers): axt.plot(x_ticks, pd_data[i], '-', marker=a_marker[i], markerfacecolor='none', color=color) axt.grid(False) customaxis(ax=axt, position='right', color=color, label='Quantity Share', scale='linear', size=fontsize, full_nrs=False, location=1.0)
def make_ax_profit_quantity(pd_profit, pd_quantity_sold, a_marker, a_color, num_sellers, gamma, fontsize=20, x_ticks=None, ax=None): color = a_color[0] pd_data = pd_profit if x_ticks is None: x_ticks = range(len(pd_data)) x_ticks = np.round(x_ticks, 2) for i in range(num_sellers): ax.plot(x_ticks, pd_data[i], '-', marker=a_marker[i], markerfacecolor='none', color=color, label='Firm %d' % (i + 1)) ax.set_xlim(min(x_ticks), max(x_ticks)) ax.set_xticks(x_ticks) customaxis(ax=ax, position='left', color=color, label='Profit', scale='linear', size=fontsize, full_nrs=False, location=0.0) ax.get_xaxis().set_major_formatter( tk.FuncFormatter(lambda x, p: format(x, ','))) ax.legend() leg = ax.get_legend() (leg.legendHandles[i].set_color('black') for i in range(num_sellers)) ax.set_title( "$\gamma$ = {} and Firm 1's initial cost is 99\% of Firm 2's".format( gamma), fontsize=fontsize + 5) # Quantity axt = ax.twinx() color = a_color[1] pd_data = pd_quantity_sold for i in range(num_sellers): axt.plot(x_ticks, pd_data[i], '-', marker=a_marker[i], markerfacecolor='none', color=color) axt.grid(False) customaxis(ax=axt, position='right', color=color, label='Quantity', scale='linear', size=fontsize, full_nrs=False, location=1.0)
def plot_1timestep_from_data(a_cost, gamma, endowment, num_sellers, num_buyers, a_price, a_quantity, a_quantity_sold, a_profit, a_buyer_pos, a_seller_pos, m_tax, m_quantity_bought): # set figure size ########################################################## nrow = 1 ncol = 2 width_scale = 9 height_scale = 6 figsize = (width_scale * ncol, height_scale * nrow) # create the plot window ########################################################## sb.set_style("darkgrid") fig = plt.figure(figsize=figsize) fig.subplots_adjust(hspace=.2, wspace=0.2) plt.rc('text', usetex=True) # set all axes instances ########################################################## circle_axis = plt.subplot2grid((nrow, ncol), (0, 0)) price_axis = plt.subplot2grid((nrow, ncol), (0, 1)) #annotate a_ax = [circle_axis, price_axis] a_annote = ['(a)', '(b)', '(c)', '(d)'] for (ax, annote) in zip(a_ax, a_annote[0:len(a_ax)]): ax.annotate(annote, xy=(-0.12, 0.96), xycoords='axes fraction', fontsize=12, ha='left', va='top') # Colors a_color = sb.color_palette("deep", (3 + num_sellers)) # Circle of buyers and sellers ############################################################ ax = circle_axis # plot a grey circle r = 1 angles = np.linspace(0, 2 * np.pi, 500) xs = r * np.sin(angles) ys = r * np.cos(angles) ax.plot(xs, ys, color='grey', linestyle='--', zorder=1) for i, s in enumerate(a_seller_pos): xcoord = [r * np.sin(2 * np.pi * s)] ycoord = [r * np.cos(2 * np.pi * s)] ax.scatter(xcoord, ycoord, marker='o', facecolor='none', color=a_color[i], s=400, zorder=3, label='Firm %d' % (i + 1)) # for each buyer, find index of his seller seller_ind = np.argmax(m_quantity_bought, axis=0) for s in range(num_sellers): a_pos_subset = a_buyer_pos[seller_ind == s] a_xcoord = [r * np.sin(2 * np.pi * a_pos_subset)] a_ycoord = [r * np.cos(2 * np.pi * a_pos_subset)] ax.scatter(a_xcoord, a_ycoord, marker='x', color=a_color[s], s=80, zorder=2, label='Buyer who bought from Firm %d' % (s + 1)) ax.set_xlim(-1.2 * r, 1.2 * r) ax.set_ylim(-1.2 * r, 1.5 * r) ax.legend(loc='center', ncol=2, frameon=False, fontsize=8, labelspacing=2) ax.axes.get_xaxis().set_visible(False) ax.axes.get_yaxis().set_visible(False) ax.axis('equal') # plot the price for each buyer ############################################################ a_xvalues = np.arange(1, num_sellers + 1) w = 0.2 fontsize = 13 ax = price_axis color = a_color[num_sellers] ax.bar(a_xvalues - w, a_price, width=.8 * w, color=color, alpha=1.0, align='center') ax.bar(a_xvalues - w, a_cost, width=.8 * w, color='black', alpha=0.2, align='center') ax.set_xlabel('') ax.set_xticks(a_xvalues) ax.set_xticklabels(['Firm %d' % i for i in a_xvalues]) [ t.set_color(i) for (i, t) in zip(a_color[0:num_sellers], ax.xaxis.get_ticklabels()) ] customaxis(ax=ax, position='left', color=color, label='Prices', scale='linear', size=fontsize, full_nrs=False, location=0.0) # plot the quantity for each seller, on same x axis as price plot, but on separate y axis ############################################################ axt = price_axis.twinx() color = a_color[num_sellers + 1] axt.grid(False) axt.bar(a_xvalues, a_quantity_sold, width=.8 * w, color=color, align='center') axt.set_xticks(a_xvalues) axt.set_ylabel('Quantities', color=color, fontsize=fontsize) customaxis(ax=axt, position='right', color=color, label='Quantities', scale='linear', size=fontsize, full_nrs=False, location=1.0) # plot the profit for each seller ############################################################ axt2 = price_axis.twinx() color = a_color[num_sellers + 2] axt2.grid(False) axt2.bar(a_xvalues + w, a_profit, width=.8 * w, color=color, align='center') axt2.set_xticks(a_xvalues) axt2.set_ylabel('Profit', color=color, fontsize=fontsize) axt2.autoscale(tight=True) customaxis(ax=axt2, position='right', color=color, label='Profit', scale='linear', size=fontsize, full_nrs=False, location=1.1)
format(int(x),','))) ax.legend() leg = ax.get_legend() (leg.legendHandles[i].set_color('black') for i in range(num_sellers)) # FIXME: title #ax.set_title("Firm 1's initial cost is 99\% of Firm 2's".format(gamma), fontsize=fontsize +5) # Quantity axt = ax.twinx() color = a_color[1] pd_data = pd_quantity_sold for i in range(num_sellers): axt.plot(range(len(pd_data)), pd_data[i], '-', marker=a_marker[i], markerfacecolor='none', color=color) axt.grid('False') customaxis(ax = axt, position = 'right', color = color, label = 'Quantity', scale = 'linear', size = fontsize, full_nrs = False, location = 1.0) # plot the cost and price ############################################################ def make_ax_cost_price(pd_cost, pd_price, pd_cournot, a_marker, a_color, num_timesteps, num_sellers, fontsize = 20, ax = None): ax.set_xlim(0, num_timesteps) # for the left y axis of axis: pd_data = pd_price color = a_color[0] for i in range(num_sellers): ax.plot(range(len(pd_data)), pd_data[i], color=color, marker = a_marker[i], markerfacecolor='none', label='') ax.spines['left'].set_color(color) ax.tick_params(axis='y', color=color)