简体   繁体   中英

Text label and add lines to python matplotlib.pyplot.imshow

I have a 2d numpy array translated to a rectangular graph with matplotlib.pyplot.imshow I am trying to achive 2 more points

  1. get text labels in each sub-rectangle in the graph
  2. mark 2 lines across the graph, like an upper and lower limit

Relevant code:

import matplotlib.pyplot as plt

plt.figure(figsize = (10,10))
plt.axis('on')

plt.imshow( res[1], interpolation='nearest', alpha =0.7)
#res[1] is a 2d numpy array (like in the screenshot bellow)


plt.jet()
#plt.colorbar()

plt.show()

I would like the labels to look something like this: 我希望标签看起来像这样

This is what I have now:

电流输出

What you need is something like this:

fig, ax = plt.subplots()
im = ax.imshow(z_matrix.T)

for i in range(z_matrix.T.shape[0]): # rows
    for j in range(z_matrix.T.shape[1]): # columns
        text = ax.text(j, i, z_matrix.T[i, j],
                       ha="center", va="center", color="black")

SOURCE: https://matplotlib.org/3.1.0/gallery/images_contours_and_fields/image_annotated_heatmap.html

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