Reputation: 25
I 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
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