import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
angles = np.linspace(0, 360, 37); cos_ = np.cos([np.deg2rad(x) for x in angles]).round(3)
I_aver = np.array([1.233, 1.346, 1.330, 1.209, 0.979, 0.674, 0.358, 0.135, 0.028, 0.001,
0.004, 0.006, 0.009, 0.043, 0.162, 0.409, 0.711, 0.999, 1.224, 1.342,
1.335, 1.182, 0.945, 0.661, 0.332, 0.130, 0.026, 0.001, 0.005, 0.007,
0.007, 0.047, 0.182, 0.412, 0.714, 0.988, 1.223]) #I_max = 1.334
plt.plot(angles, I_aver, color='#9A30DA', markerfacecolor='#30308B',
linestyle='-', markersize=5, marker='s', markeredgewidth=0)
fig, ax = plt.subplots(ncols=4, nrows=1, figsize=(16, 3))
for i in range(4):
x_range = [round(x,3) for x in (cos_*cos_)[i*9:(i+1)*9]]
y_range = [round(y,3) for y in (I_aver/1.334)[i*9:(i+1)*9]]
ax[i,0].plot(x_range[:,0], y_range[:,0], 'o')
plt.show()
报错情况如下:
Traceback (most recent call last):
File "D:\pycharm\projects\pythonProject\数据可视化\其他可视化资源\数据分析实战\大物实验.py", line 20, in <module>
ax[i,0].plot(x_range[:,0], y_range[:,0], 'o')
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
尝试多次,发现直接输出图像可行,数据没有问题,但是一用循环就会报错。请问该如何解决,谢谢!
for i in range(4):
x_range = [round(x,3) for x in (cos_*cos_)[i*9:(i+1)*9]]
y_range = [round(y,3) for y in (I_aver/1.334)[i*9:(i+1)*9]]
ax[i].plot(x_range, y_range, 'o')
plt.show()