In: Computer Science
Loading Pandas DataFrames and Creating Multiple Plots and Subplots x1 y1 y1_pred x2 y2 y2_pred x3 y3 y3_pred x4 y4 y4_pred 0 10 8.04 8.001000 10 9.14 8.000909 10 7.46 7.999727 8 6.58 7.001 1 8 6.95 7.000818 8 8.14 7.000909 8 6.77 7.000273 8 5.76 7.001 2 13 7.58 9.501273 13 8.74 9.500909 13 12.74 9.498909 8 7.71 7.001 3 9 8.81 7.500909 9 8.77 7.500909 9 7.11 7.500000 8 8.84 7.001 4 11 8.33 8.501091 11 9.26 8.500909 11 7.81 8.499455 8 8.47 7.001 5 14 9.96 10.001364 14 8.10 10.000909 14 8.84 9.998636 8 7.04 7.001 6 6 7.24 6.000636 6 6.13 6.000909 6 6.08 6.000818 8 5.25 7.001 7 4 4.26 5.000455 4 3.10 5.000909 4 5.39 5.001364 19 12.50 12.500 8 12 10.84 9.001182 12 9.13 9.000909 12 8.15 8.999182 8 5.56 7.001 9 7 4.82 6.500727 7 7.26 6.500909 7 6.42 6.500545 8 7.91 7.001 10 5 5.68 5.500545 5 4.74 5.500909 5 5.73 5.501091 8 6.89 7.001 Questions
1 Calculate min and max for axis base of data in dataframe
2. Create a single plot of four scatter diagrams
3. Create a new visualization that combines the four previous plots in to one large plot with four subplots
In case of any queries, please revert back.
I guess you have loaded the dataset using pd.read_csv.
I will show you python codes for the following 3 questions. As the dataset cannot be copied, I wont be able to show the outputs, but the code will work once you load the dataset correctly.
1. We have 2 axis that are axis 1 and 0. Now, if the dataframe is stored in df, we can use min and max functions of pandas.
minVarX = df.min(axis=0)
This finds minimum horizontally
minVarY = df.min(axis=0)
This finds minimum vertically.
maxVarX = df.min(axis=0)
This finds maximum horizontally
maxVarY = df.min(axis=0)
This finds maximum vertically.
2. Now, we have to find scatter plots in the same diagram.
I will use matplotlib for this questions. :-
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2,2)
axs[0, 0].scatter(x1, y1)
axs[0, 1].scatter(x2, y2)
axs[1, 0].scatter(x3, y3)
axs[1, 1].scatter(x4, y4)
3. Now we will create a master scatter plot with all datasets but of diferent colors :-
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2,2)
plt.scatter(x1,y1, color='r')
plt.scatter(x2,y2, color='g')
plt.scatter(x3,y3, color='b')
plt.scatter(x4,y4, color='y')
plt.show()
If you face any problem, please revert back. I will solve it ASAP.