Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f9b9930

Browse files
committed
added solution from gallery/colormap reference
1 parent 630086a commit f9b9930

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

tutorials/colors/colormaps.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,19 +204,18 @@
204204

205205

206206
def plot_color_gradients(cmap_category, cmap_list):
207+
# Create figure and adjust figure height to number of colormaps
207208
nrows = len(cmap_list)
208-
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6, 0.29 * nrows))
209-
fig.subplots_adjust(top=1, bottom=0, left=0.2, right=0.99)
210-
axs[0].text(0.5, 0.5, cmap_category + " colormaps", fontsize=14,
211-
transform=axs[0].transAxes, horizontalalignment="center",
212-
verticalalignment="center")
209+
figh = 0.35 + 0.15 + (nrows + (nrows - 1) * 0.1) * 0.22
210+
fig, axs = plt.subplots(nrows=nrows + 1, figsize=(6.4, figh))
211+
fig.subplots_adjust(top=1 - 0.35 / figh, bottom=0.15 / figh,
212+
left=0.2, right=0.99)
213+
axs[0].set_title(cmap_category + ' colormaps', fontsize=14)
213214

214-
for ax, name in zip(axs[1:], cmap_list):
215+
for ax, name in zip(axs, cmap_list):
215216
ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(name))
216-
pos = list(ax.get_position().bounds)
217-
x_text = pos[0] - 0.01
218-
y_text = pos[1] + pos[3]/2.
219-
fig.text(x_text, y_text, name, va='center', ha='right', fontsize=10)
217+
ax.text(-0.01, 0.5, name, va='center', ha='right', fontsize=10,
218+
transform=ax.transAxes)
220219

221220
# Turn off *all* ticks & spines, not just the ones with colormaps.
222221
for ax in axs:

0 commit comments

Comments
 (0)