Plotting with different data structures
plotting with numpy, pandas and ColumnDataSource
Creating a plot using Numpy
Instead of the simple array of data points, we can use np.array
to fill into a plot. For demonstration purposes, we generate 10 data points that follow the pattern of a sinus. Once we created the dataset we are going to interpolate to create 50 datapoints following the same pattern. Linear Interpolation is a method of curve fitting using linear polynomials to construct new data points within the range of a discrete set of known data points. Let us look to a very simple example
Creating a plot using Pandas DataFrame
Columns of a pandas dataframe are nothing more than a numpy array and can be used in a similar way. Below you find the iris dataset to be imported. This is a pandas dataframe. From that dataframe the column 'petal_length' and the column 'petal_width' are selected. These are arrays which can be plotted the same way we used the arrays in a scatter plot before.
Creating plot using ColumnDataSource
Instead of a dictionary, you can parse a pandas dataframe as well.
Last updated
Was this helpful?