Python Plotly:图像在屏幕底部重复

时间:2019-05-08 22:45:37

标签: python plotly

我使用Plotly生成了一个股票图表,并且该图像在图像的底部被复制了。下面是我的源代码。

        ...
        data = {'date': [x for x in self.ohlc],
                'open': [float(x['open']) for x in self.ohlc],
                'high': [float(x['high']) for x in self.ohlc],
                'low': [float(x['low']) for x in self.ohlc],
                'close':[float(x['close']) for x in self.ohlc],
                'volume':[float(x['volume']) for x in self.ohlc]}
        df = DataFrame(data)

        INCREASING_COLOR = '#17BECF'
        DECREASING_COLOR = '#7F7F7F'
        data = [dict(type='candlestick',
                     open=df.open,
                     high=df.high,
                     low=df.low,
                     close=df.close,
                     x=df.index,
                     yaxis='y2',
                     name=self.title,
                     increasing=dict(line=dict(color=INCREASING_COLOR)),
                     decreasing=dict(line=dict(color=DECREASING_COLOR)),)]
        # layout
        layout = dict()
        fig = dict(data=data, layout=layout)
        fig['layout'] = dict()
        fig['layout']['plot_bgcolor'] = 'rgb(250, 250, 250)'
        fig['layout']['xaxis'] = dict(rangeselector=dict(visible=True))
        fig['layout']['yaxis'] = dict(domain=[0, 0.2], showticklabels=False)
        fig['layout']['yaxis2'] = dict(domain=[0.2, 0.8])
        fig['layout']['legend'] = dict(orientation='h', y=0.9, x=0.3, yanchor='bottom')
        fig['layout']['margin'] = dict(t=40, b=40, r=40, l=40)

        # volume color
        colors = []
        for i in range(len(df.close)):
            if i != 0:
                if df.close[i] > df.close[i - 1]:
                    colors.append(INCREASING_COLOR)
                else:
                    colors.append(DECREASING_COLOR)
            else:
                colors.append(DECREASING_COLOR)

        # volume
        fig['data'].append(dict(x=df.index,
                                y=df.volume,
                                marker=dict(color=colors),
                                type='bar',
                                yaxis='y',
                                name='Volume'))
        # write chart
        filename = '{}.png'.format(self.symbol)
        pio.write_image(fig, filename)

我得到了这张图片。我不知道我想在图像底部放一个小的副本。

enter image description here

0 个答案:

没有答案