jupyanno icon indicating copy to clipboard operation
jupyanno copied to clipboard

parsing zoom data is not robust

Open kmader opened this issue 6 years ago • 0 comments

crashes when x or y has None/nulls in it

from matplotlib.patches import Rectangle
for col_name in 'xy':
    for i in range(2):
        zooms_df['{}_{}'.format(col_name, i)] = zooms_df[col_name].map(
            lambda x: x[i])
    zooms_df['d_{}'.format(col_name, i)] = zooms_df[col_name].map(
        lambda x: max(x)-min(x))
fig, ax1 = plt.subplots(1, 1, figsize=(10, 10))
ax1.set_xlim([zooms_df['x_0'].min(), zooms_df['x_1'].max()])
ax1.set_ylim([zooms_df['y_0'].min(), zooms_df['y_1'].max()])
max_cat = zooms_df['img_cat'].max()


for c_idx, c_rows in zooms_df.groupby('img_idx'):
    bonus_args = {'label': c_idx}
    for _, c_row in c_rows.iterrows():
        ax1.add_patch(Rectangle(xy=(c_row['x_0'], c_row['y_0']),
                                width=c_row['d_x'], height=c_row['d_y'],
                                color=plt.cm.hot(c_row['img_cat']/max_cat),
                                **bonus_args,
                                alpha=0.1))
        bonus_args = {}
ax1.set_title('Map of Zoom Regions')
ax1.legend()

kmader avatar Aug 28 '18 19:08 kmader