Matplotlib pyplot散射轴是无序的

时间:2017-12-23 17:19:38

标签: python pandas numpy matplotlib

为什么我的散点图在Y轴上看起来像这样?我希望它以有序的方式进行!

这是代码:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
x = pd.DataFrame.from_dict({"Main":{183: 12.0, 145: 9.8, 130: 8.2, 182: 11.9, 146: 9.9, 99: 22.9, 3: 22.0, 9: 22.5, 186: 12.2, 77: 21.7, 69: 21.0, 87: 22.7, 139: 9.2, 5: 22.0, 152: 10.4, 61: 22.5, 229: 26.1, 14: 23.1, 230: 26.2, 201: 12.7, 103: 23.1, 101: 23.0, 199: 12.8, 188: 12.3, 37: 21.3, 2: 22.0, 179: 11.5, 66: 20.9, 144: 9.7, 16: 23.2, 196: 12.6, 15: 23.1, 216: 24.8, 110: 23.2, 133: 8.5, 165: 12.3, 107: 23.2, 109: 23.2, 224: 26.5, 6: 22.1, 90: 22.7, 91: 22.7, 223: 26.4, 13: 23.0, 35: 21.2, 173: 10.6, 58: 22.4, 160: 11.0, 39: 21.5, 232: 26.2, 120: 22.2, 202: 12.7, 169: 9.9, 170: 10.1, 8: 22.4, 137: 8.9, 197: 12.6, 65: 20.9, 73: 21.3, 93: 22.9, 114: 23.3, 180: 11.7, 159: 11.0, 127: 8.1, 60: 22.5, 42: 21.6, 72: 21.2, 105: 23.2, 55: 22.1, 221: 26.3, 121: 22.2, 207: 23.4, 29: 20.9, 151: 10.4, 166: 12.3, 122: 22.5, 27: 20.9, 218: 26.1, 79: 21.9, 32: 21.0, 154: 10.6, 210: 24.3, 205: 22.8, 131: 8.3, 56: 22.2, 185: 12.1, 123: 22.6, 135: 8.7, 234: 24.8, 36: 21.3, 108: 23.2, 83: 22.3, 172: 10.4, 147: 10.0, 136: 8.8, 7: 22.2, 49: 21.9, 85: 22.5, 18: 23.3, 231: 26.5, 134: 8.6, 43: 21.7, 82: 22.2, 89: 22.7, 235: 23.3, 141: 9.4, 22: 21.0, 17: 23.3, 195: 12.6, 174: 10.8, 162: 11.6, 95: 22.7, 97: 22.7, 23: 21.0, 140: 9.3, 142: 9.5, 98: 22.8, 132: 8.4, 129: 8.2, 104: 23.2, 96: 22.7, 158: 10.9, 40: 21.5, 215: 25.2, 4: 22.0, 0: 22.0, 12: 22.9, 217: 25.9, 222: 26.4, 80: 22.0, 70: 21.1, 233: 26.2, 138: 9.0, 193: 12.5, 92: 22.8, 192: 12.5, 124: 22.5, 59: 22.4, 150: 10.3, 176: 11.1, 225: 26.5, 38: 21.4, 167: 9.9, 44: 21.7, 113: 23.3, 112: 23.3, 214: 25.2, 155: 10.7, 52: 21.9, 220: 26.3, 63: 22.6, 74: 21.3, 184: 12.0, 187: 12.3, 41: 21.6, 26: 20.9, 33: 21.1, 11: 22.8, 117: 23.1, 190: 12.4, 177: 11.3, 34: 21.1, 219: 26.2, 53: 22.0, 161: 11.1}})
y = pd.DataFrame.from_dict({'Real': {183: 9.3, 145: 8.4, 130: 8.1, 182: 9.3, 146: 8.4, 99: 21.5, 3: 22.2, 9: 22.2, 186: 9.3, 77: 21.4, 69: 21.2, 87: 21.6, 139: 8.3, 5: 22.2, 152: 8.5, 61: 20.9, 229: 23.4, 14: 22.2, 230: 23.4, 201: 9.3, 103: 21.7, 101: 21.6, 199: 9.4, 188: 9.4, 37: 20.4, 2: 22.2, 179: 9.2, 66: 21.2, 144: 8.4, 16: 22.1, 196: 9.4, 15: 22.1, 216: 23.2, 110: 21.7, 133: 8.2, 165: 8.8, 107: 21.7, 109: 21.7, 224: 24.1, 6: 22.2, 90: 21.5, 91: 21.5, 223: 24.0, 13: 22.2, 35: 20.5, 173: 9.1, 58: 20.7, 160: 8.6, 39: 20.4, 232: 23.5, 120: 20.4, 202: 9.3, 169: 9.0, 170: 9.1, 8: 22.2, 137: 8.3, 197: 9.4, 65: 21.1, 73: 21.3, 93: 21.5, 114: 21.8, 180: 9.2, 159: 8.6, 127: 8.0, 60: 20.8, 42: 20.4, 72: 21.3, 105: 21.7, 55: 20.5, 221: 24.0, 121: 20.3, 207: 23.1, 29: 20.6, 151: 8.5, 166: 8.8, 122: 20.5, 27: 20.7, 218: 23.9, 79: 21.4, 32: 20.6, 154: 8.5, 210: 23.3, 205: 22.8, 131: 8.1, 56: 20.6, 185: 9.3, 123: 20.7, 135: 8.2, 234: 22.0, 36: 20.5, 108: 21.7, 83: 21.5, 172: 9.1, 147: 8.4, 136: 8.2, 7: 22.2, 49: 20.4, 85: 21.5, 18: 22.1, 231: 23.7, 134: 8.2, 43: 20.4, 82: 21.4, 89: 21.5, 235: 20.4, 141: 8.3, 22: 20.9, 17: 22.2, 195: 9.4, 174: 9.2, 162: 9.1, 95: 21.4, 97: 21.3, 23: 20.8, 140: 8.3, 142: 8.4, 98: 21.4, 132: 8.1, 129: 8.1, 104: 21.7, 96: 21.3, 158: 8.6, 40: 20.4, 215: 23.5, 4: 22.2, 0: 22.1, 12: 22.2, 217: 23.7, 222: 23.9, 80: 21.4, 70: 21.2, 233: 23.4, 138: 8.3, 193: 9.4, 92: 21.5, 192: 9.4, 124: 20.6, 59: 20.8, 150: 8.5, 176: 9.2, 225: 24.1, 38: 20.4, 167: 9.0, 44: 20.4, 113: 21.7, 112: 21.7, 214: 23.4, 155: 8.5, 52: 20.4, 220: 24.0, 63: 20.9, 74: 21.4, 184: 9.3, 187: 9.4, 41: 20.4, 26: 20.7, 33: 20.6, 11: 22.2, 117: 21.5, 190: 9.4, 177: 9.2, 34: 20.5, 219: 23.9, 53: 20.4, 161: 8.6}})
ax.scatter(x.Main, y, s=100, marker="x")

enter image description here

EDIT2:缺少数据......

1 个答案:

答案 0 :(得分:0)

鉴于数据,该问题现在可以重现。

您正在尝试绘制完整的DataFrame y。这使matplotlib感到困惑。 而是选择要绘制的列,

ax.scatter(x.Main, y.Real, s=100, marker="x")

结果如下:

enter image description here