Home > Net >  Plotting vertical line on an image clears the image leaving only the vertical lines
Plotting vertical line on an image clears the image leaving only the vertical lines

Time:06-14

Hi All I want to plot vertical lines on a plotted image. I am using ax.vlines() to plot the vertical lines on the image, however the resulting plot clears the image leaving only the vertical lines on the figure as showed in the attached image. Any suggestions to correct this are welcomed. Below is my sample code:

def display_image(img, SavePath):
    vmin, vmax = np.min(img), np.max(img)
    fig, ax = plt.subplots(figsize=(4, 4))
    img = ax.imshow(img, cmap='gray', aspect="auto", extent=[0, image.shape[1], img.shape[0]/10, 0], vmin=vmin, vmax=vmax)
    divider = make_axes_locatable(ax)
    cax    = divider.append_axes("right",size="5%",pad=0.05)
    plt.colorbar(img,ax=ax,cax=cax)
    plt.tick_params(labelsize=6)
    for label in  ax.get_xticklabels() ax.get_yticklabels():
        label.set_fontsize(6)
    ax.vlines(x=[0, 120, 256],  ymin=2, ymax=0, colors='r')   ## this line plots the 3 vertical lines
    plt.savefig(SavePath 'Image', facecolor=fig.get_facecolor(), 
                        edgecolor=fig.get_edgecolor(), transparent=True)

enter image description here

  • Related