Skip to content

Commit

Permalink
fixed some weird interactions with colorbar.
Browse files Browse the repository at this point in the history
places ticks for colorbars should be done using cbar.set_ticks. Be careful when passing a colourmap as normalization occurs
  • Loading branch information
AdamBanham committed Jul 4, 2022
1 parent 1cf999d commit 450c755
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/vispm/extensions/dotted/event_histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from matplotlib.axes import Axes
from matplotlib.cm import get_cmap, ScalarMappable
from matplotlib.colors import Colormap
from matplotlib.colors import Colormap,ListedColormap,Normalize
from mpl_toolkits.axes_grid1 import make_axes_locatable

DEFAULT_COLORMAP = get_cmap('rainbow')
Expand Down Expand Up @@ -148,17 +148,13 @@ def draw(self,x_data:List[float], y_data:List[float],sequences:List[List[Sequenc
cbar_orientation = 'vertical'
cax = divider.append_axes('right', size='10%', pad=0.2)


# add colourbar to axes
tickers = list(range(0,len(seen_activities)))
cbar = self._axes.get_figure().colorbar(ScalarMappable(cmap=self._colourer._cm), ticks=tickers, orientation=cbar_orientation, cax=cax)
tickers = [ t/len(tickers)+(0.5/len(tickers)) for t in tickers ]
if cbar_orientation == 'horizontal':
cbar.ax.set_xticks(tickers)
cbar.ax.set_xticklabels([ sa['act'] for sa in seen_activities], fontdict={'fontsize' : 6})
else:
cbar.ax.set_yticks(tickers)
cbar.ax.set_yticklabels([ sa['act'] for sa in seen_activities], fontdict={'fontsize' : 6})

norm = Normalize(vmin=0, vmax=max(tickers))
cbar = self._axes.get_figure().colorbar(ScalarMappable(cmap=ListedColormap(colours), norm=norm), ticks=tickers, orientation=cbar_orientation, cax=cax)
tickers = cbar.get_ticks()
cbar.set_ticks(tickers, labels=[ sa['act'] for sa in seen_activities], fontsize=6)
# adjust tick position if needed
if self._direction == self.Direction.NORTH:
cbar.ax.get_xaxis().set_ticks_position('top')

Expand Down Expand Up @@ -228,6 +224,7 @@ def draw(self,x_data:List[float], y_data:List[float],sequences:List[List[Sequenc
)
self._axes.set_xlim([min_x,max_x])
else:
# adjust ticks for trace identifiers
portion = (max_x - min_x) / 8.0
ticks = [min_x] + [int(np.floor((min_x + (i*portion)))) for i in range(1,8)] + [max_x]
if orientation == 'horizontal':
Expand Down

0 comments on commit 450c755

Please sign in to comment.