def plot_without_z(df, x, y, z, count_table, bins_x, bins_y, x_is_numeric, y_is_numeric, ordered_x_values, ordered_y_values, normalization_by_all=False, log=False, maximal_bubble_size=4000):
if normalization_by_all:
count_table /= count_table.sum().sum()
else:
count_table = count_table.transpose()
for col in count_table.columns:
count_table[col] /= count_table[col].sum()
count_table = count_table.transpose()
if log:
count_table = np.log(count_table)
maximal_bubble_size /= 2
size_factor = maximal_bubble_size/count_table.max().max()
count_table_long = pd.melt(count_table.reset_index(), id_vars=x)
x_values_dict = {x:i for i, x in enumerate(ordered_x_values)} \
if not x_is_numeric else {xx:get_point(xx) for xx in ordered_x_values}
y_values_dict = {x:i for i, x in enumerate(ordered_y_values)} \
if not y_is_numeric else {xx: get_point(xx) for xx in ordered_y_values}
xticks = np.arange(count_table.shape[0]) if not x_is_numeric else [get_point(xx) for xx in ordered_x_values]
yticks = np.arange(count_table.shape[1]) if not y_is_numeric else [get_point(xx) for xx in ordered_y_values]
xticklabels = ordered_x_values if not x_is_numeric else [get_point(xx) for xx in ordered_x_values]
yticklabels = ordered_y_values if not y_is_numeric else [get_point(xx) for xx in ordered_y_values]
count_table_long[x] = count_table_long[x].map(x_values_dict)
count_table_long[y] = count_table_long[y].map(y_values_dict)
plt.scatter(count_table_long[x], count_table_long[y], s=size_factor*count_table_long['value'],
c=count_table_long['value'], cmap='cool')
return count_table_long, xticks, yticks, xticklabels, yticklabels
评论列表
文章目录