【问题标题】:Set matplotlib backend from Pandas从 Pandas 设置 matplotlib 后端
【发布时间】:2017-03-11 09:19:38
【问题描述】:

我目前面临以下问题。我有几个 Python 脚本,它们使用 Python 模块 Pandas 绘制一些有用的信息,该模块使用 Matplotlib

据我所知,matplotlib 让我们按照this question 接受的答案中的描述设置其后端。

我想从 Pandas 设置 matplotlib 后端:

  • 有可能吗?
  • 我该怎么做?

编辑 1: 顺便说一句,我的代码看起来像:

import pandas as pd
from pandas import DataFrame, Series

class MyPlotter():
    def plot_from_file(self, stats_file_name, f_name_out, names,
                   title='TITLE', x_label='x label', y_label='y label'):
        df = pd.read_table(stats_file_name, index_col=0, parse_dates=True,
                       names= names)

        plot = df.plot(lw=2,colormap='jet',marker='.',markersize=10,title=title,figsize=(20, 15))

        plot.set_xlabel(x_label)
        plot.set_ylabel(y_label)

        fig = plot.get_figure()

        fig.savefig(f_name_out)

        plot.cla()

【问题讨论】:

  • 我认为您之所以被否决,是因为您的问题需要更具体:您想要完成什么,到目前为止您尝试了什么,它是如何失败的?
  • 我认为标题已经足够具体了,无论如何我都会完成这篇文章。
  • fwiw,我经常使用 pandas 和 matplotlib,这个问题对我来说很有意义。在没有任何其他证据的情况下,我必须假设反对者是对这些软件包没有太多经验的人——可能会在审查队列中触发快乐的高代表用户(我在世界上最不喜欢的人)。

标签: python pandas matplotlib


【解决方案1】:

我刚刚应用了this question 上发布的解决方案,并且成功了。

换句话说,我的代码导入看起来像:

import pandas as pd
from pandas import DataFrame, Series

应用解决方案后,导入看起来如下:

import pandas as pd
from pandas import DataFrame, Series
import matplotlib
matplotlib.use('pdf')
import matplotlib.pyplot as plt

我知道我在回答我自己的问题,但我这样做是为了以防有人发现它有用。

【讨论】:

    猜你喜欢
    • 2020-05-31
    • 2011-06-23
    • 1970-01-01
    • 2013-07-21
    • 1970-01-01
    • 2019-05-06
    • 1970-01-01
    • 2012-03-30
    • 2017-03-31
    相关资源
    最近更新 更多