Reputation: 21
I am very new to Python and start to learn matplotlib recently. I have a dataset which have one 5 independent variables and 1 dependent variable. I want to create a stacked histogram which can show the variable distribution within independent variable.
Here is my raw data- Country, age, new_use, source and total_pages_visited are independent variables. Converted is dependent variable. I want to create separate stacked histogram for each independent variables. And in each histogram, it shows the distribution of variable and mark the different category of 'converted' in different color.
Upvotes: 0
Views: 1556
Reputation: 2364
I think what you want is stacked bar plot and you can use pandas
to achieve it.
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
df = pd.DataFrame(np.asarray([[1,2],[3,4],[5,6]]),index=['A','B','C'], columns=['Converted-Yes', 'Converted-No'])
df.plot.bar(stacked=True)
plt.show()
The above code generates the plot:
Upvotes: 1