Data visualization with clear bars on a histogram?

1 week ago 9
ARTICLE AD BOX

I am making a histogram where all the bars are overlapped, but even with the transparency lowered for the bars, it still looks like a mess to me. I thought if I could make the bars themselves transparent fill and the edge color different colors for different datasets, it would make it easier to see?

But I can only figure out how to set the overall transparency to 0 (which includes the edge color so there's no bar anywhere), or to fill it with white (which still makes it hard to see the colors stacked in the back - attached).

How could I accomplish this transparent bar with a colored outline? Is this even the best way to show this?

import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as mtick import seaborn as sns import pandas as pd # import excel file excel_file_path = '/content/Chondrule Sizes (comparison).xlsx' # read excel file df_excel = pd.read_excel(excel_file_path, sheet_name='All Diameters (raw)') # select data data_for_plot_8 = df_excel['MIL 15322 (EL3)'] data_for_plot_7 = df_excel['QUE 94594 (EL3)'] data_for_plot_6 = df_excel['ALH 85119 (EL3)'] data_for_plot_5 = df_excel['MAC 88180 (EL3)'] data_for_plot_4 = df_excel['PCA 91020 (EL3)'] data_for_plot_3 = df_excel['ALH 84170 (EH3)'] data_for_plot_2 = df_excel['PCA 91085 (EH3)'] data_for_plot_1 = df_excel['PCA 91238 (EH3)'] # create plot plt.figure(figsize=(12, 7)) bins = np.linspace(0, 3300, 67) # plot histograms - probability density plt.hist(data_for_plot_1, bins, alpha=0.3,label='PCA 91238 (EH3)', linewidth=1.5, color='white', edgecolor='red', density=True) plt.hist(data_for_plot_2, bins, alpha=0.3,label='PCA 91085 (EH3)', linewidth=1.5, color='white',edgecolor='darkorange', density=True) plt.hist(data_for_plot_3, bins, alpha=0.3,label='ALH 84170 (EH3)', linewidth=1.5, color='white',edgecolor='gold', density=True) plt.hist(data_for_plot_4, bins, alpha=0.3,label='PCA 91020 (EL3)', linewidth=1.5, color='white',edgecolor='yellow', density=True) plt.hist(data_for_plot_5, bins, alpha=0.3,label='MAC 88180 (EL3)', linewidth=1.5, color='white',edgecolor='green', density=True) Data with colored bars (original)plt.hist(data_for_plot_6, bins, alpha=0.3,label='ALH 85119 (EL3)', linewidth=1.5, color='white',edgecolor='lightseagreen', density=True) plt.hist(data_for_plot_7, bins, alpha=0.3,label='QUE 94594 (EL3)', linewidth=1.5, color='white',edgecolor='deepskyblue', density=True) plt.hist(data_for_plot_8, bins, alpha=0.3,label='MIL 15322 (EL3)', linewidth=1.5, color='white',edgecolor='indigo', density=True) # change y-axis to percent instead of probability density bin_width = bins[1] - bins[0] def to_percent(y, position): return f"{y * bin_width * 100:.0f}%" plt.gca().yaxis.set_major_formatter(mtick.FuncFormatter(to_percent)) # plot format plt.legend(loc='upper right') plt.xlabel('Diameter (µm)') plt.ylabel('Percent %') plt.title('Size Frequency Distribution of Chondrule Diameters (µm)') plt.grid(True, linestyle='--', alpha=0.6) plt.show()

Colored bars (original):

White bars, colored outline:

Read Entire Article