-1

I am currently facing the following issue. I have a couple of Python scripts that plot some useful information using the Python module Pandas which uses Matplotlib .

As far as I understand matplotlib let set its backend as described on the accepted answer to this question.

I would like to set the matplotlib backend from Pandas:

  • Is it possible?
  • How can I do it?

EDIT 1: By the way my code looks like:

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()
Community
  • 1
  • 1
pafede2
  • 1,626
  • 4
  • 23
  • 40
  • 1
    I think the reason you're getting downvotes is that your question needs to be more specific: what are you trying to accomplish, what have you tried so far, how did it fail? – ASGM Oct 28 '16 at 13:40
  • I supposed that the title was specific enough, any way I am going to complete the post. – pafede2 Oct 28 '16 at 13:43
  • fwiw, i use pandas and matplotlib regularly, and this question makes total sense to me. without any other evidence, i must assume that the downvoters were people without much experience with these packages -- probably trigger-happy high-rep users in the review queue (my least favorite people in the world). – abcd Jun 07 '17 at 23:24

1 Answers1

2

I've just applied the solution posted on the this question and it worked out.

In others words, my code imports looked as:

import pandas as pd
from pandas import DataFrame, Series

After applying the solution the imports look as:

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

I know I am answering my own question, but I am doing so in case someone can find it useful.

Community
  • 1
  • 1
pafede2
  • 1,626
  • 4
  • 23
  • 40