1
$\begingroup$

I have the CSV's of data. I want to plot the distribution of every attribute or a single one to compare the distribution from other CSV's, Since all attributes are the same but the distribution is different from each other because I have made the synthetic data using the original one. Just like shown below that one attribute distribution is different from the other, I don't know the name of this chart. How could I plot this : enter image description here

Code I tried so far:

    data=pd.read_csv(r'/content/drive/MyDrive/census-income.data.csv',names=['age','class of worker','detailed industry recode','detailed occupation recode','education','wage per hour','enroll in edu inst last wk','martial status','major industry code','major occupation code','race','hispanic origin','sex','member of labour union','reason for unemployment','full or part time employment stat','capital gains','capital losses','divdends from stock','tax filer status','region of previous residence','state of previous residence','detailed household and family stat','detailed household summary in household','instance weight','migration code-change in msa','migration code-change in reg','migration code-move within reg','live in this house 1 year ago',' migration prev res in sunbelt','num persons worked for employer','family members under 18','country of birth father','country of birth mother','country of birth self','citizenship','own business or self employed','fill inc questionnaire for veterans admin','veterans benefits','weeks worked in year','year','income'])
    data=data.drop(['state of previous residence','migration code-change in msa','migration code-change in reg','migration code-move within reg',' migration prev res in sunbelt','country of birth father','country of birth mother','country of birth self','instance weight'],axis=1)
    s_data=pd.read_csv('/content/drive/MyDrive/SyntheticData/SDV/SDV_TRAIN_DATA.csv')
    d_data=pd.read_csv('/content/drive/MyDrive/SyntheticData/Data Synthesizer/DataSynthesizerCensusTrain.csv')
    sp_data=pd.read_csv('/content/drive/MyDrive/SyntheticData/Synthpop/CensusTrainData.csv')
    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    
    # example data
    x = np.arange(len(data))
    
    fig, ax = plt.subplots(figsize=(50,48))
    
    ax.bar(data['age'], x,color="red",  edgecolor="None", linewidth=4, label='Original Data')
    ax.bar(s_data['age'],x,color="None", edgecolor="blue", linewidth=4, label='Synthetic Data Vault')
    # ax.bar(d_data['age'],x,color="None", edgecolor="green", linewidth=4, label='Data Synthesizer')
    # ax.bar(x, sp_data, color="None", edgecolor="green", linewidth=2, label='Synthpop')
    ax.legend()
    
    plt.show()
$\endgroup$
2
  • $\begingroup$ Can you please put the code here, not a screenshot of it (see here) $\endgroup$
    – Albo
    Commented Apr 8, 2021 at 6:29
  • $\begingroup$ If you find my answer useful, I'd appreciate if you'd mark it as correct. Thank you! $\endgroup$
    – Albo
    Commented Apr 18, 2021 at 9:50

1 Answer 1

2
$\begingroup$

Use (more information in the docs):

import matplotlib.pyplot as plt
import numpy as np

# example data
x = list(range(14))
y1 = np.arange(14)
y2 = np.arange(14)[::-1]
y3 = [8 for x in range(14)]

# Interesting part
fig, ax = plt.subplots()

ax.bar(x, y1, color="red",  edgecolor="None", linewidth=2, label='1')
ax.bar(x, y2, color="None", edgecolor="blue", linewidth=2, label='2')
ax.bar(x, y3, color="None", edgecolor="green", linewidth=2, label='3')
ax.legend()

plt.show()

enter image description here

$\endgroup$
4
  • $\begingroup$ What if I want to print the distribution of a column of Data Frame since I have multiple CSV's so I am taking the single distribution from each and then I am plotting $\endgroup$
    – Hamza
    Commented Apr 7, 2021 at 19:01
  • $\begingroup$ Can you provide some sample data, otherwise it's hard to follow... $\endgroup$
    – Albo
    Commented Apr 8, 2021 at 6:02
  • $\begingroup$ I have 33 columns , and length of the data is 199523. I have edited my post . Kindly check $\endgroup$
    – Hamza
    Commented Apr 8, 2021 at 6:16
  • $\begingroup$ @Hamza Thank you, yet it's not entirely clear to me what is the problem now? $\endgroup$
    – Albo
    Commented Apr 8, 2021 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.