High School

Solve the following tasks using Python:

**Plotting Curves**

a) Draw a spiral.

b) Draw an "infinity" shape.

c) Draw a "flower-like" shape.

**Scatter Plots**

a) Make a scatter plot of the first two columns, with a distinct marker color for each flower type.

b) Make a quiver plot, representing sepal data by position, petal data by arrows, and flower type by arrow color.

c) Make a 3D scatter plot of the sepal and petal data, with the fourth column represented by marker size.

Answer :

We have used the matplotlib library for plotting. These Python scripts should produce the desired plots for each question. Make sure to replace the sample data with your actual data when using these scripts.

Let's go through each question one by one:

a) Draw a spiral:

python

import matplotlib.pyplot as plt

import numpy as np

theta = np.linspace(0, 10 * np.π, 1000)

radius = θ

x = radius * np.cosθ

y = radius * np.sinθ

plt.plot(x, y)

plt.title('Spiral')

plt.xlabel('x')

plt.ylabel('y')

plt.axis('equal')

plt.show()

b) Draw an "[infinity]" shape:

python

import matplotlib.pyplot as plt

import numpy as np

θ = np.linspace(-2xnp.π, 2*np.π, 1000)

radius = 1

x = radius x np.sin(theta)

y = radius x np.sin(theta) x np.cos(theta)

plt.plot(x, y)

plt.title('Infinity Shape')

plt.xlabel('x')

plt.ylabel('y')

plt.axis('equal')

plt.show()

c) Draw a "flower-like" shape:

python

import matplotlib.pyplot as plt

import numpy as np

θ = np.linspace(0, 2*np.π, 1000)

radius = 1 + 0.2 * np.cos(6 * θ)

x = radius * np.cosθ

y = radius * np.sinθ

plt.plot(x, y)

plt.title('Flower-like Shape')

plt.xlabel('x')

plt.ylabel('y')

plt.axis('equal')

plt.show()

a) Make a scatter plot of the first two columns, with a distinct marker color for each flower type:

python

import matplotlib.pyplot as plt

import numpy as np

# Assuming you have data for the scatter plot in the form of a NumPy array called 'data'

# Columns 0 and 1 represent the x and y coordinates respectively, and column 2 represents the flower type

# Sample data

data = np.array([

[5.1, 3.5, 0],

[4.9, 3.0, 1],

[4.7, 3.2, 2],

# ... Add more data here ...

])

# Unique flower types

flower_types = np.unique(data[:, 2])

# Scatter plot with distinct marker color for each flower type

for flower_type in flower_types:

x = data[data[:, 2] == flower_type][:, 0]

y = data[data[:, 2] == flower_type][:, 1]

plt.scatter(x, y, label=f'Flower Type {flower_type}')

plt.title('Scatter plot of the first two columns')

plt.xlabel('Column 0')

plt.ylabel('Column 1')

plt.legend()

plt.show()

c) Make a quiver plot, representing sepal data by position, petal data by arrows, and flower type by arrow color:

python

import matplotlib.pyplot as plt

import numpy as np

# Assuming you have data for the quiver plot in the form of a NumPy array called 'data'

# Columns 0 and 1 represent the x and y coordinates of sepal data respectively,

# Columns 2 and 3 represent the x and y components of petal data respectively,

# and column 4 represents the flower type.

# Sample data

data = np.array([

[5.1, 3.5, 1.4, 0.2, 0],

[4.9, 3.0, 1.4, 0.2, 1],

[4.7, 3.2, 1.3, 0.2, 2],

# ... Add more data here ...

])

# Separate data for sepal and petal

sepal_data = data[:, :2]

petal_data = data[:, 2:4]

flower_types = data[:, 4]

# Quiver plot

plt.quiver(sepal_data[:, 0], sepal_data[:, 1], petal_data[:, 0], petal_data[:, 1], flower_types, pivot='mid', cmap='viridis')

plt.title('Quiver plot with flower type by arrow color')

plt.xlabel('Sepal x')

plt.ylabel('Sepal y')

plt.show()

```

d) Make a 3D scatter plot of the sepal and petal data, with the 4th column represented by marker size:

python

import matplotlib.pyplot as plt

import numpy as np

# Assuming you have data for the 3D scatter plot in the form of a NumPy array called 'data'

# Columns 0, 1, and 2 represent the x, y, and z coordinates respectively, and column 3 represents the marker size.

# Sample data

data = np.array([

[5.1, 3.5, 1.4, 10],

[4.9, 3.0, 1.4, 15],

[4.7, 3.2, 1.3, 5],

# ... Add more data here ...

])

x = data[:, 0]

y = data[:, 1]

z = data[:, 2]

marker_size = data[:, 3]

# 3D scatter plot

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

ax.scatter(x, y, z, s=marker_size)

ax.set_xlabel('Sepal x')

ax.set_ylabel('Sepal y')

ax.set_zlabel('Petal z')

plt.title('3D Scatter plot with marker size representing the 4th column')

plt.show()

learn more about scatter plot-

https://brainly.com/question/17029728

#SPJ4