Skip to content

Issue about the 'colormap' plot type #76

@qiuzanlin

Description

@qiuzanlin

**Hello,

I am trying to learn this tools but I face with some problems about the colormap plot.

The issue occured with I run this code:**

tml.plot_polarisation_vectors(x, y, u, v, image=image,
unit_vector=False, save=None,
plot_style='colormap',
overlay=False, title='Vector Arrows', cmap='viridis',
monitor_dpi=50)

It gives me an error as following:


ValueError Traceback (most recent call last)
Cell In[7], line 4
1 #Vector magnitude plot with colormap viridis:
----> 4 tml.plot_polarisation_vectors(x, y, u, v, image=image,
5 unit_vector=False, save=None,
6 plot_style='colormap', cbar_vmax=1,cbar_vmin=0.1,
7 overlay=False, title='Vector Arrows', cmap='viridis',
8 monitor_dpi=50)

File D:\Python\Python39\lib\site-packages\temul\topotem\polarisation.py:584, in plot_polarisation_vectors(x, y, u, v, image, sampling, units, plot_style, overlay, unit_vector, vector_rep, degrees, angle_offset, save, title, color, cmap, cbar_vmin, cbar_vmax, alpha, image_cmap, monitor_dpi, no_axis_info, invert_y_axis, ticks, scalebar, antialiased, levels, remove_vectors, quiver_units, pivot, angles, scale_units, scale, headwidth, headlength, headaxislength, width, minshaft, minlength)
582 sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
583 sm.set_array([])
--> 584 cbar = plt.colorbar(mappable=sm, fraction=0.046, pad=0.04,
585 drawedges=False)
586 cbar.set_ticks(ticks)
587 cbar.ax.set_ylabel(vector_label)

File ~\AppData\Roaming\Python\Python39\site-packages\matplotlib\pyplot.py:2326, in colorbar(mappable, cax, ax, **kwargs)
2321 if mappable is None:
2322 raise RuntimeError('No mappable was found to use for colorbar '
2323 'creation. First define a mappable such as '
2324 'an image (with imshow) or a contour set ('
2325 'with contourf).')
-> 2326 ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kwargs)
2327 return ret

File ~\AppData\Roaming\Python\Python39\site-packages\matplotlib\figure.py:1285, in FigureBase.colorbar(self, mappable, cax, ax, use_gridspec, **kwargs)
1283 if cax is None:
1284 if ax is None:
-> 1285 raise ValueError(
1286 'Unable to determine Axes to steal space for Colorbar. '
1287 'Either provide the cax argument to use as the Axes for '
1288 'the Colorbar, provide the ax argument to steal space '
1289 'from it, or add mappable to an Axes.')
1290 fig = ( # Figure of first axes; logic copied from make_axes.
1291 [*ax.flat] if isinstance(ax, np.ndarray)
1292 else [*ax] if np.iterable(ax)
1293 else [ax])[0].figure
1294 current_ax = fig.gca()

ValueError: Unable to determine Axes to steal space for Colorbar. Either provide the cax argument to use as the Axes for the Colorbar, provide the ax argument to steal space from it, or add mappable to an Axes.

I thinks the problem is about the mappable. It turns out that the code thinks the mappable is none. I try to solve this problem but I can't. I am not sure why this issue occur. Is it because of the python or matplotlib version? (My python is 3.9 and matplotlib is 3.8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions