xxxxxxxxxx
import numpy as npimport matplotlib.pyplot as plt
# Create data
N = 500x = np.random.rand(N)
y = np.random.rand(N)
colors = (0,0,0)
area = np.pi*3
# Plot
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.title('Scatter plot pythonspot.com')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
x_axis = ['value_1', 'value_2', 'value_3', ]
y_axis = ['value_1', 'value_2', 'value_3', ]
plt.scatter(x_axis, y_axis)
plt.title('title name')
plt.xlabel('x_axis name')
plt.ylabel('y_axis name')
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
def draw_scatterplot(x_values, y_values):
plt.scatter(x_values, y_values, s=20)
plt.title("Scatter Plot")
plt.xlabel("x values")
plt.ylabel("y values")
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
x = np.random.rand(20)
y = np.random.rand(20)
z = x*y
fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x, y, z, linewidths=1, alpha=.7, edgecolor='k', s = 200, c=z)
plt.show()
xxxxxxxxxx
df.plot(x="col1", y="col2", kind="scatter", title = "Some Title")
plt.show()
xxxxxxxxxx
import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2 # 0 to 15 point radii
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
# Example data
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# Creating a scatter plot
plt.scatter(x, y)
# Adding labels and title
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Scatter Plot')
# Displaying the plot
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
height = [66, 64, 30, 67, 32, 3.9, 3.1, 8.9, 7.7]
diameter = [10.2, 11, 6.9, 12, 2.8, 3.9, 3.1, 8.9, 7.7]
plt.scatter(height, diameter)
plt.show()
xxxxxxxxxx
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
# Plotting with 2 variables
ax.scatter(df1["col1"], df1["col2"], color="red", label="df1")
ax.scatter(df2["col1"], df2["col2"], color="blue", label="df2")
ax.set_xlabel("X axis label")
ax.set_ylabel("Y axis label")
ax.legend()
plt.show()
# Plotting with 3 variables
ax.scatter(df["col1"], df["col2"], c=df.col3) # c represents the third variable
ax.set_xlabel("X axis label")
ax.set_ylabel("Y axis label")
plt.show()