Monday, 3 October 2022

6 a). Apply and explore various plotting functions on UCI data sets. Density and contour plots

 6 a). Apply and explore various plotting functions on UCI data sets. Density and contour plots

Aim

          To apply and explore various plotting functions like Density and contour plots on datasets.

Procedure

There are three Matplotlib functions that can be helpful for this task: plt.contour for contour plots, plt.contourf for filled contour plots, and plt.imshow for showing images

A contour plot can be created with the plt.contour function. It takes three arguments: a grid of x values, a grid of y values, and a grid of z values.

The x and y values represent positions on the plot, and the z values will be represented by the contour levels.

Perhaps the most straightforward way to prepare such data is to use the np.meshgrid function, which builds two-dimensional grids from one-dimensional arrays.

Next standard line-only contour plot and for color the lines can be color-coded by specifying a colormap with the cmap argument. 

Additionally, we'll add a plt.colorbar() command, which automatically creates an additional axis with labeled color information for the plot.

Program

%matplotlib inline

import matplotlib.pyplot as plt

plt.style.use('seaborn-white')

import numpy as np

def f(x, y):

    return np.sin(x) ** 10 + np.cos(10 + y * x) * np.cos(x)

x = np.linspace(0, 5, 50)

y = np.linspace(0, 5, 40)

X, Y = np.meshgrid(x, y)

Z = f(X, Y)

plt.contour(X, Y, Z, colors='black');

Output

 

plt.contour(X, Y, Z, 20, cmap='RdGy');

Output

plt.contourf(X, Y, Z, 20, cmap='RdGy')

plt.colorbar();

Output

Result

Various plotting functions like Density and contour plots on datasets are successfully executed.

2 comments:

CCS 365 Software Defined Network Lab Manual

 CCS 365 Software Defined Network Lab Manual 1) Setup your own virtual SDN lab i) Virtualbox/Mininet Environment for SDN - http://mininet.or...