简体   繁体   中英

How to set markersize in plt.imshow()

I have the following problem: I want to plot an adjacency matrix using a colormap. Now I want do adjust the markersize, because you cannot really see the dots in the picture since the matrix is really big . How can I do this? Using spy(), this works like this.

plt.spy(adj, markersize = 1)

I want to have something like this:

plt.imshow(adj, cmap = colormap, markersize= 1)

This however, doesnt work. Thanks

You may use a scatter plot, which allows to set the markersize using the s argument.

ax.scatter(X,Y,c=z, s=36, marker="s")

An example comparing a spy, imshow and scatter plot.

import matplotlib.pyplot as plt
import numpy as np

fig, (ax1,ax2,ax3) = plt.subplots(ncols=3, figsize=(8,4))

z = np.random.rand(20, 20)
X,Y = np.meshgrid(np.arange(z.shape[1]),np.arange(z.shape[0]))
z[5] = 0.
z[:, 12] = 0.

ax1.spy(z, markersize=5, precision=0.1, origin="lower")
ax2.imshow(z, origin="lower")
ax3.scatter(X,Y,c=z, s=36, marker="s")
ax3.set_aspect("equal")
ax3.margins(0)

ax1.set_title("spy")
ax2.set_title("imshow")
ax3.set_title("scatter")

plt.show()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM