cheind/tf-matplotlib

Plot with more of 3 channels

luissalgueiro opened this issue · 4 comments

Hello @cheind

I installed your package and tried to customize the scatter example, but I could not plot more than 3 subplots. For example, adding more than 3 colors it only the first 3.

How can I solve the issue?

Thanks

Luis

hard to see what's wrong, share some minimal code please

Hello @cheind, thanks for the fast replay.

The idea is to see every channel of a Tensor with shape [Batch, Height, Widht, Channels] where the number of channels >=4

// number of channels for the tensor to be plotted
channels = 4

with tf.Session(graph=tf.Graph()) as sess:

    @tfmpl.figure_tensor
    def draw_scatterss(scaled, channels): 
        '''Draw scatter plots. One for each color.'''  
        figs= tfmpl.create_figures(channels, figsize=(7,7))
        
        for idx, f in enumerate(figs):
            ax = f.add_subplot(111)
            ax.imshow(scaled[:,:,idx], cmap='gray')
        return figs  

    aa = tf.placeholder(tf.float32,[14,14,None])          #     or')
    image_tensor = draw_scatterss(aa, channels)
    image_summary = tf.summary.image('scatter', image_tensor)
    all_summaries = tf.summary.merge_all()

    os.makedirs('log', exist_ok=True)
    now = datetime.now()
    logdir = "log/" + now.strftime("%Y%m%d-%H%M%S") + "/"
    writer = tf.summary.FileWriter(logdir, sess.graph)
    
    #create a tensor with random noise
    aa1 = np.random.random((14,14,channels))
    
    summary = sess.run(all_summaries, feed_dict={aa: aa1 })
    writer.add_summary(summary, global_step=0)
    writer.flush()

Hi @cheind,

I think I have the solution. Only add channels to the max_outputs in the summary

image_summary = tf.summary.image('scatter', image_tensor, max_outputs=channels)

Great code by the way, I learned a lot.

Thanks

Great, closing!