1
1
from bokeh .plotting import figure , show , save , output_notebook , output_file
2
2
from bokeh .models import HoverTool , ColumnDataSource , CategoricalColorMapper , ColorBar , LinearColorMapper
3
- from bokeh .models import FuncTickFormatter , FixedTicker , Legend , BasicTickFormatter , Panel , Tabs
3
+ from bokeh .models import FuncTickFormatter , FixedTicker , Legend , BasicTickFormatter , TabPanel , Tabs
4
4
from bokeh .palettes import Turbo256 as palette_umap
5
5
from bokeh .transform import linear_cmap
6
6
import matplotlib .colors as mpt_colors
@@ -93,8 +93,8 @@ def swarmplot(df, xlim, ylim, title="Swarmplot", legend_header="", **kwargs):
93
93
df ['edgecolor' ] = df ['color_values' ].apply (col_edge_get )
94
94
size = 6
95
95
96
- plot_figure = figure (title = title , plot_width = 900 ,
97
- plot_height = 500 , tools = ('' ),
96
+ plot_figure = figure (title = title , width = 900 ,
97
+ height = 500 , tools = ('' ),
98
98
x_axis_type = "log" , x_range = xlim , y_range = ylim ,
99
99
x_axis_label = 'Single cell attention' )
100
100
plot_figure .add_tools (HoverTool (tooltips = """
@@ -151,7 +151,7 @@ def multi_swarmplot(df, xlim, ylim, title, path_save=None, **kwargs):
151
151
title ,
152
152
legend_header = "Annotated cell type" ,
153
153
** kwargs )
154
- tab1 = Panel (child = swarm_regular , title = "Full annotation" )
154
+ tab1 = TabPanel (child = swarm_regular , title = "Full annotation" )
155
155
156
156
df_simplified = df .copy ()
157
157
df_simplified ['color_values' ] = df_simplified ['color_values' ].apply (
@@ -163,7 +163,7 @@ def multi_swarmplot(df, xlim, ylim, title, path_save=None, **kwargs):
163
163
title ,
164
164
legend_header = "Annotated cell group" ,
165
165
** kwargs )
166
- tab2 = Panel (child = swarm_simplified , title = "Reduced annotation" )
166
+ tab2 = TabPanel (child = swarm_simplified , title = "Reduced annotation" )
167
167
168
168
if path_save is None :
169
169
# if no path_save is given, show
@@ -197,7 +197,7 @@ def export_swarmplot(
197
197
ax .set_xscale ('log' )
198
198
yrange = ylim [0 ] - ylim [1 ]
199
199
ax .set_xlim (xlim [0 ], xlim [1 ])
200
- ax .set_ylim (ylim [1 ], yrange - ylim [1 ] )
200
+ ax .set_ylim (ylim [1 ]* 0.5 , ylim [0 ] * 0.5 )
201
201
ax .spines ['top' ].set_visible (False )
202
202
ax .spines ['left' ].set_visible (False )
203
203
ax .spines ['right' ].set_visible (False )
@@ -279,74 +279,74 @@ def export_swarmplot(
279
279
fontsize = FONTSIZE )
280
280
leg ._legend_box .align = "left"
281
281
282
- # plot in highlighted images
283
- # draw out lines and plot images
284
- if highlight_idx is not None :
285
- im_buffer = {}
286
- for identifier in highlight_idx :
287
- cell = df .loc [df ['im_id' ] == identifier ].iloc [0 ]
288
- x , y = cell .x , cell .y
289
- class_lbl = cell .color_values
290
- ax2 .plot ([x , x ], [y , y + yrange ], c = 'lightgray' , zorder = 5 )
291
-
292
- # load and display image
293
- im = Image .open (cell .im_path )
294
- im_buffer [x ] = im
295
-
296
- ax2 .scatter (
297
- x ,
298
- y ,
299
- color = col_get (class_lbl ),
300
- linewidth = 0.5 ,
301
- s = dotsize ,
302
- zorder = 10 ,
303
- marker = shape_get_matplotlib (class_lbl ),
304
- edgecolors = col_edge_get (class_lbl ))
305
-
306
- class_lbl = cell .color_values_pooled
307
- ax2 .scatter (
308
- x ,
309
- y + yrange ,
310
- color = col_get (class_lbl ),
311
- linewidth = 0.5 ,
312
- s = dotsize ,
313
- zorder = 10 ,
314
- marker = shape_get_matplotlib (class_lbl ),
315
- edgecolors = col_edge_get (class_lbl ))
316
-
317
- # shift images a little bit to improve optics
318
- global xpoints
319
- xpoints = sorted (im_buffer .keys ())
320
-
321
- def log_x_dist (x1 , x2 ):
322
- if min (x1 , x2 ) <= 0 :
323
- return 10000
324
- return math .log10 (max (x1 , x2 ) / min (x1 , x2 ))
325
-
326
- def f_positions (shifts ):
327
- global xpoints
328
-
329
- # calculate distances to close points
330
- xpoints_shifted = [xpoints [x ] * shifts [x ]
331
- for x in range (len (xpoints ))]
332
- el_dists = np .array ([log_x_dist (
333
- xpoints_shifted [x ], xpoints_shifted [x + 1 ]) for x in range (len (xpoints ) - 1 )])
334
- mean_dist = np .mean (el_dists )
335
- dist_loss = np .sum (np .square (el_dists - mean_dist ))
336
-
337
- return dist_loss
338
-
339
- # calculate coordinates
340
- shift_images = fmin (f_positions , np .array ([1 ] * len (xpoints )))
341
-
342
- # add images
343
- for x in xpoints :
344
- im = im_buffer [x ]
345
- ab = AnnotationBbox (OffsetImage (im , zoom = 0.5 ), (x *
346
- shift_images [xpoints .index (x )], yrange +
347
- ylim [1 ]), frameon = True , pad = 0.0 )
348
- ab .set_zorder (10 )
349
- ax2 .add_artist (ab )
282
+ # # plot in highlighted images
283
+ # # draw out lines and plot images
284
+ # if highlight_idx is not None:
285
+ # im_buffer = {}
286
+ # for identifier in highlight_idx:
287
+ # cell = df.loc[df['im_id'] == identifier].iloc[0]
288
+ # x, y = cell.x, cell.y
289
+ # class_lbl = cell.color_values
290
+ # ax2.plot([x, x], [y, y + yrange], c='lightgray', zorder=5)
291
+
292
+ # # load and display image
293
+ # im = Image.open(cell.im_path)
294
+ # im_buffer[x] = im
295
+
296
+ # ax2.scatter(
297
+ # x,
298
+ # y,
299
+ # color=col_get(class_lbl),
300
+ # linewidth=0.5,
301
+ # s=dotsize,
302
+ # zorder=10,
303
+ # marker=shape_get_matplotlib(class_lbl),
304
+ # edgecolors=col_edge_get(class_lbl))
305
+
306
+ # class_lbl = cell.color_values_pooled
307
+ # ax2.scatter(
308
+ # x,
309
+ # y + yrange,
310
+ # color=col_get(class_lbl),
311
+ # linewidth=0.5,
312
+ # s=dotsize,
313
+ # zorder=10,
314
+ # marker=shape_get_matplotlib(class_lbl),
315
+ # edgecolors=col_edge_get(class_lbl))
316
+
317
+ # # shift images a little bit to improve optics
318
+ # global xpoints
319
+ # xpoints = sorted(im_buffer.keys())
320
+
321
+ # def log_x_dist(x1, x2):
322
+ # if min(x1, x2) <= 0:
323
+ # return 10000
324
+ # return math.log10(max(x1, x2) / min(x1, x2))
325
+
326
+ # def f_positions(shifts):
327
+ # global xpoints
328
+
329
+ # # calculate distances to close points
330
+ # xpoints_shifted = [xpoints[x] * shifts[x]
331
+ # for x in range(len(xpoints))]
332
+ # el_dists = np.array([log_x_dist(
333
+ # xpoints_shifted[x], xpoints_shifted[x + 1]) for x in range(len(xpoints) - 1)])
334
+ # mean_dist = np.mean(el_dists)
335
+ # dist_loss = np.sum(np.square(el_dists - mean_dist))
336
+
337
+ # return dist_loss
338
+
339
+ # # calculate coordinates
340
+ # shift_images = fmin(f_positions, np.array([1] * len(xpoints)))
341
+
342
+ # # add images
343
+ # for x in xpoints:
344
+ # im = im_buffer[x]
345
+ # ab = AnnotationBbox(OffsetImage(im, zoom=0.5), (x *
346
+ # shift_images[xpoints.index(x)], yrange +
347
+ # ylim[1]), frameon=True, pad=0.0)
348
+ # ab.set_zorder(10)
349
+ # ax2.add_artist(ab)
350
350
351
351
ax .text (
352
352
x = 0.01 ,
@@ -597,8 +597,8 @@ def umap(
597
597
df ['info' ] = df [data_column ]
598
598
size = 8
599
599
600
- plot_figure = figure (title = title , plot_width = 900 ,
601
- plot_height = 700 , tools = ('pan, wheel_zoom, reset' ),
600
+ plot_figure = figure (title = title , width = 900 ,
601
+ height = 700 , tools = ('pan, wheel_zoom, reset' ),
602
602
aspect_scale = 2 )
603
603
604
604
# plot_figure.yaxis.visible = False
0 commit comments