Myplotlib图簇

时间:2019-07-19 06:57:45

标签: python plot subplot

我试图绘制两个子图。由于某种原因,当我使用特定范围的数据(并且仅使用一个特定范围)时,子图会聚在图的右边缘(如下图所示)。使用除100以外的任何其他时间范围的数据不会产生此问题。我的代码在图片下方。我无法解决此问题,因此欢迎您的帮助!!!

enter image description here

                   plt.style.use('dark_background')
                   fig, axs = plt.subplots(2, 1, sharex=True)
                   fig.subplots_adjust(hspace=0)
                   if pllong == []:
                       print("No long positions were opened.")
                   else:
                       axs[0].scatter(rsipllongdate, rsipllong, label = "Long position", color='green')
                   if plshort == []:
                       print("No short positions were opened.")
                   else:
                       axs[0].scatter(rsiplshortdate, rsiplshort, label = "Short position", color='red')
                   if plliquidate == []:
                       print("No liquidations took place.")
                   else:
                       axs[0].scatter(rsiplliquidatedate, rsiplliquidate, label = "Liquidation", color = 'gold')
                   axs[0].plot(datelist, close, label="Close", color = "white", linewidth = 0.9, zorder = 0)
                   axs[1].plot(datelist, rsidf, label="RSI", color = "white", linewidth = 0.9, zorder = 0)
                   if logscale == 1:
                       axs[0].semilogy()
                   plt.xticks(rotation=90)
                   plt.axhline(xmin = 0, xmax = 1, y=70, color='g', linestyle='-', linewidth = 0.8)
                   plt.axhline(xmin = 0, xmax = 1, y=30, color='r', linestyle='-', linewidth = 0.8)
                   plt.fill_between(datelist, 70, 30, zorder = 0, color = "slategrey")
                   axs[0].grid(linestyle='-', linewidth=0.4)
                   axs[1].grid(linestyle='-', linewidth=0.4)
                   fig.legend(loc='upper center', ncol=3, borderaxespad=0, frameon=False)
                   plt.autoscale()
                   plt.show()
                   plt.style.use('dark_background')
                   plt.xlabel("Date")
                   plt.ylabel("Net Profit/Loss (%)")
                   plt.xticks(rotation=90)
                   plt.grid(linestyle='-', linewidth=0.4)
                   plt.plot(datelist, rsipldf, label="Profit/Loss", color = "skyblue", zorder = 0)
                   plt.axhline(xmin = 0, xmax = 1, y= 0, color='white', linestyle='-', linewidth = 0.8)
                   plt.legend(loc='lower left', bbox_to_anchor= (0.0, 1.01), ncol=2, borderaxespad=0, frameon=False)
                   plt.autoscale()
                   plt.show()

0 个答案:

没有答案