简体   繁体   English

plt.plot 分散 plot output 问题

[英]plt.plot scatter plot output issue

After running this block of code, I am getting 'Conversion Error' message:运行此代码块后,我收到“转换错误”消息:

    import matplotlib.pyplot as plt
    plt.figure(figsize=(12.2, 4.5))
    plt.title('Buy and Sell Plot', fontsize = 18)
    plt.plot(df['Close'], label = 'Close Price', color = 'blue', 
     alpha = 0.35)
    plt.plot(ShortEMA, label = 'Short/Fast EMA', color = 'red', 
    alpha = 0.35)
    plt.plot(MiddleEMA, label = 'Middle/Medium EMA', color = 
    'orange', alpha = 0.35)
    plt.plot(LongEMA, label = 'Long/Slow EMA', color = 'green', 
    alpha = 0.35)
    plt.scatter(df.index, df['Buy'], color = 'green', 
    marker='^', alpha = 1)
    plt.scatter(df.index, df['Sell'], color = 'red', marker='v', 
    alpha = 1)
    plt.xlabel('Date', fontsize = 18)
    plt.ylabel('Close Price', fontsize = 18)
    plt.show()

Any insight would be most appreciated任何见解将不胜感激

This is probably happening due to the " plt.scatter(df.index, (...)" part. If you run type(df.index) you'll see it's a pandas.core.indexes.range.RangeIndex , not an array. Try running it with np.asarray(auc_df.index) instead, hope it'll fix the issue!这可能是由于“ plt.scatter(df.index, (...)” 部分而发生的。如果您运行type(df.index)您会看到它是pandas.core.indexes.range.RangeIndex ,而不是一个数组。尝试使用np.asarray(auc_df.index)运行它,希望它能解决问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM