Skip to content

Commit

Permalink
update colorbar
Browse files Browse the repository at this point in the history
  • Loading branch information
waltsims committed Jan 10, 2024
1 parent c3742e2 commit 8d820f2
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions examples/at_array_as_sensor/at_array_as_sensor.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"import numpy as np\n",
"\n",
"from kwave.data import Vector\n",
Expand Down Expand Up @@ -176,11 +177,23 @@
" 3: 'PML Mask',\n",
"}\n",
"\n",
"colorbar = plt.colorbar(c, ticks=list(labels.keys()), ax=ax)\n",
"colorbar.ax.set_yticklabels(list(labels.values()))\n",
"bounds = np.linspace(0, len(labels), len(labels)+1)\n",
"norm = mpl.colors.BoundaryNorm(bounds, cmap.N)\n",
"\n",
"ax.set_xticks([])\n",
"ax.set_yticks([])\n",
"ax2 = fig.add_axes([0.95, 0.1, 0.03, 0.8])\n",
"cb = mpl.colorbar.ColorbarBase(ax2, cmap=cmap, norm=norm,\n",
" spacing='proportional', ticks=bounds, boundaries=bounds, format='%1i')\n",
"\n",
"# Update the title and label as before\n",
"ax.set_title('Simulation Layout')\n",
"ax2.set_ylabel('Simulation Components [-]', size=12)\n",
"\n",
"# Calculate the middle points for each segment of the colorbar\n",
"mid_points = [(bounds[i] + bounds[i+1])/2 for i in range(len(bounds)-1)]\n",
"\n",
"# Set the new tick positions and labels\n",
"ax2.set_yticks(mid_points)\n",
"ax2.set_yticklabels(list(labels.values()))\n",
"\n",
"plt.show()"
]
Expand Down Expand Up @@ -239,7 +252,15 @@
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8d820f2

Please sign in to comment.