Return a value and show plot when running a function

Viewed 19

So while writing my functions, for analyzing the data I like to built the functionality to display data, it helps me debug.

In matplotlib with jupyter notebook I can use the following code to show a plot and return a value:

import matplotlib.pyplot as plt
def testwithmatplotlib(num, plotdata = True):
    x = np.arange(num)
    y = x * x
    if plotdata:
        plt.scatter(x, y)
        plt.show()
    return(y)
resmat = testwithmatplotlib(8)   

with matplotlib

In holoviews, with jupyter notebook I am using IPython display module as below. I am not sure if this is good method or no, please suggest if there is a better way to do this.

import holoviews as hv
def testwithholoviews(num, plotdata = True):
    x = np.arange(num)
    y = x * x
    if plotdata:
        aplot = hv.Scatter((x, y))
        hv.IPython.display.display_html(aplot)
        plt.show()
    return(y)

 
reshol = testwithholoviews(8)   

with holoviews

0 Answers
Related