awdaD ASDF
awdaD ASDF

Reputation: 25

Creating multiple matplotlib charts from one function which is taking in a list of data

enter image description hereI am basically taking a csv file and need to make a bar chart out of each column from the chart. What I currently have is the function I have created takes each numerical column and creates a bar chart of each unique element and how many times it has occurred in the column of the data source.

My problem is that every new graph I plot it overlaps and is from the same "figure".

Is there any way to make a function that will create the chart plot and make it "unique" to its other fellow charts

Upvotes: 0

Views: 229

Answers (2)

tetukowski
tetukowski

Reputation: 111

It seems that you want to create figure each time your function read and plot the column. I suggest that you use the OOP of Matplotlib. For example use

from matplotlib import pyplot as plt    
fig, ax = plt.subplots()
#then in any place of your code, you can use, for example
ax.plot(x,y)

To make a different figure for each loop, put the fig, ax = plot.subplots() inside the loop. If you want to make various plots into single figure, create the figure outside the loop. Here is perfect tutorial: https://realpython.com/python-matplotlib-guide/

Consider give a minimal-example, so that others can help you better.

Upvotes: 0

awdaD ASDF
awdaD ASDF

Reputation: 25

plt.figure(postition) worked for me

Upvotes: 0

Related Questions