johndoe
johndoe

Reputation: 103

Access attributes of a matplotlib plot made through pandas plot function

Say I have a pandas dataframe and I plot it with matplotlib via the pandas built-in function plot:

mydata = list(zip([1, 2, 3], [4, 5, 6]))
dataframe = pandas.DataFrame(mydata)
barchart = dataframe.plot(kind = 'bar')

How do I access the color of the bars?

More generally, how do I access all the attributes?

E.g. I can get the background color with barchart.get_axis_bgcolor() and I can set it to grey with barchart.set_axis_bgcolor('grey'), but what about all the other attributes?

Upvotes: 0

Views: 263

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

To change the color of a series you can do this with colors,

mydata = list(zip([1, 2, 3], [4, 5, 6]))
dataframe = pd.DataFrame(mydata) 
barchart = dataframe.plot(kind = 'bar',color=['maroon','purple'])

However, with the barchart variable you have a handle on the axes, now you can use get_children() to get a hold of any patches, text, axis, or any other object in the chart to modify just about anything you want.

Upvotes: 1

Related Questions