Skip to content

Commit bbbe797

Browse files
committed
Format colorbar properly
1 parent 7a71a8a commit bbbe797

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

notebooks/photometry/04.01.02-aperture-photometry-xdf.ipynb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,18 @@
813813
" aperture.plot(color='white', alpha=0.7, axes=ax1)\n",
814814
"\n",
815815
"# Define the colorbar\n",
816-
"cbar = plt.colorbar(fitsplot, fraction=0.046, pad=0.04, ticks=LogLocator(subs=range(10)))\n",
817-
"labels = ['$10^{-4}$'] + [''] * 8 + ['$10^{-3}$'] + [''] * 8 + ['$10^{-2}$']\n",
818-
"cbar.ax.set_yticklabels(labels)\n",
816+
"cbar = plt.colorbar(fitsplot, fraction=0.046, pad=0.04, ticks=LogLocator())\n",
817+
"\n",
818+
"def format_colorbar(bar):\n",
819+
" # Add minor tickmarks\n",
820+
" bar.ax.yaxis.set_minor_locator(LogLocator(subs=range(1, 10)))\n",
821+
"\n",
822+
" # Force the labels to be displayed as powers of ten and only at exact powers of ten\n",
823+
" bar.ax.set_yticks([1e-4, 1e-3, 1e-2])\n",
824+
" labels = [f'$10^{{{pow:.0f}}}$' for pow in np.log10(bar.ax.get_yticks())]\n",
825+
" bar.ax.set_yticklabels(labels)\n",
826+
"\n",
827+
"format_colorbar(cbar)\n",
819828
"\n",
820829
"# Define labels\n",
821830
"cbar.set_label(r'Flux Count Rate ({})'.format(xdf_image.unit.to_string('latex')), \n",

0 commit comments

Comments
 (0)