Complete the code to create a scatter plot using pandas.
import pandas as pd import matplotlib.pyplot as plt data = {'x': [1, 2, 3, 4], 'y': [10, 20, 25, 30]} df = pd.DataFrame(data) df.plot.scatter(x='x', y=[1]) plt.show()
The scatter plot requires the y-axis column name. Here, it is 'y'.
Complete the code to set the color of points in the scatter plot.
import pandas as pd import matplotlib.pyplot as plt data = {'height': [150, 160, 170, 180], 'weight': [50, 60, 65, 70]} df = pd.DataFrame(data) df.plot.scatter(x='height', y='weight', c=[1]) plt.show()
The 'c' parameter sets the color of points. It accepts color names like 'blue'.
Fix the error in the code to correctly plot a scatter plot with size variation.
import pandas as pd import matplotlib.pyplot as plt data = {'age': [20, 25, 30, 35], 'income': [2000, 2500, 3000, 3500], 'score': [10, 20, 30, 40]} df = pd.DataFrame(data) df.plot.scatter(x='age', y='income', s=[1]) plt.show()
The 's' parameter expects numeric values for sizes. Passing the Series df['score'] works correctly.
Fill both blanks to create a scatter plot with custom marker and transparency.
import pandas as pd import matplotlib.pyplot as plt data = {'temp': [30, 35, 40, 45], 'sales': [100, 150, 200, 250]} df = pd.DataFrame(data) df.plot.scatter(x='temp', y='sales', marker=[1], alpha=[2]) plt.show()
The marker 'x' is a valid shape, and alpha 0.5 sets transparency to 50%.
Fill all three blanks to create a scatter plot with color, size, and title.
import pandas as pd import matplotlib.pyplot as plt data = {'speed': [5, 10, 15, 20], 'distance': [50, 100, 150, 200], 'weight': [100, 200, 300, 400]} df = pd.DataFrame(data) ax = df.plot.scatter(x=[1], y=[2], s=[3], c='red') ax.set_title('Speed vs Distance') plt.show()
The x-axis is 'speed', y-axis is 'distance', and sizes come from the 'weight' column as a Series.