import matplotlib.pyplot as plt
# Define the first_derivative and iterations data
first_derivative = [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j, 5 + 5j]
iterations = [0, 1, 2, 3, 4]
# Split the first_derivative into real and imaginary parts
x = [val.real for val in first_derivative]
y = [val.imag for val in first_derivative]
# Create a figure and axis for the 3D plot
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Plot the data as a scatter plot
ax.scatter(x, y, iterations, c='r', marker='o')
# Set the x, y, and z labels
ax.set_xlabel('Real Part')
ax.set_ylabel('Imaginary Part')
ax.set_zlabel('Number of Iterations')
# Show the plot
plt.show()
旧代码
使用matplotlib库:
import matplotlib.pyplot as plt
# Example values of first derivative and the number of iterations
first_derivative = [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j, 5 + 5j]
iterations = [0, 1, 2, 3, 4]
# Plot the values of first derivative vs number of iterations
plt.plot(iterations, first_derivative, 'ro')
plt.xlabel('Number of iterations')
plt.ylabel('First derivative')
plt.title('First derivative vs Number of iterations')
plt.show()
1条答案
按热度按时间sr4lhrrt1#
根据您的评论更新:
旧代码
使用
matplotlib
库:传递给plot函数的
ro
参数是一个格式字符串,用于指定要绘制的数据点的格式。该格式字符串由两个字符组成:r
:将数据点的颜色指定为red
。o
:将数据点的形状指定为circles
。可以使用不同的格式字符串为数据点指定不同的颜色和形状。例如,
bx
将指定blue crosses
,g^
将指定green triangles
,依此类推。