TwitterAxe.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:StockTalk3 作者: xenu256 项目源码 文件源码
def savePlot(self, name, width=6, height=4.5):
        timestamps = []
        sentiment = []
        tweets = []
        for data_point in self.timeSeries:
            timestamps.append(datetime.strptime(data_point["TIME"], '%Y-%m-%d %H:%M:%S'))
            sentiment.append(data_point["SENTIMENT"])
            tweets.append(data_point["TWEETS"])

        # Plot setup
        ax1 = plt.figure(figsize=(width, height)).add_subplot(111)
        ax1.spines["top"].set_visible(False)
        ax1.get_xaxis().tick_bottom()
        ax1.get_yaxis().tick_left()
        ax1.xaxis.set_major_formatter(DateFormatter('%m-%d %H:%M'))
        lns1 = ax1.plot(timestamps, sentiment, color="dimgrey", lw=0.75, label="Sentiment")
        plt.yticks(fontsize=8)
        plt.ylim(ymin=-1, ymax=1)
        plt.xticks(rotation=50, fontsize=8)
        ax2 = ax1.twinx()
        lns2 = ax2.plot(timestamps, tweets, color="dodgerblue", lw=0.5, label="Tweets")
        ax2.margins(0.05)
        plt.yticks(fontsize=8)

        # Labeling
        ax1.legend(lns1+lns2, ['Sentiment', 'Tweets'], loc=0, frameon=False, fontsize=6)
        ax1.set_ylabel("Sentiment", weight="light", rotation=90, fontsize=9, labelpad=1)
        ax2.set_ylabel("Tweets", weight="light", rotation=-90, fontsize=9, labelpad=15)
        plt.title("Tweet Sentiment", weight ="light", fontsize=12, y=1.08)
        plt.ylim(ymin=0)
        plt.tight_layout()
        file_name = join(BASE_PATH, "outputs", name+".png")
        plt.savefig(file_name)
        print("Saved plot {}".format(file_name))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号