import pandas as pd
import plotly.express as px
import plotly.figure_factory as ff
import numpy as np
# Load the dataset
file_path = 'C:\\Users\\loydt\\Downloads\\Superstore Sales Dataset.csv'
data = pd.read_csv(file_path)
# Create the histogram with a logarithmic x-axis
fig1 = px.histogram(data, x='Sales', nbins=1000, title='Sales Distribution - Histogram',
opacity=0.7, log_x=True)
# Customize the histogram's color
fig1.update_traces(marker_color='orange', selector=dict(type='histogram'))
# Create a KDE plot using figure_factory
kde_data = [data['Sales']]
group_labels = ['Sales']
# Adding the KDE overlay to the histogram
kde_fig = ff.create_distplot(kde_data, group_labels, show_rug=False, curve_type='kde', bin_size=0.5)
# Add the KDE line to the histogram figure
for trace in kde_fig['data']:
fig1.add_trace(trace)
# Updating the layout to set a darker background and other enhancements
fig1.update_layout(
xaxis_title='Sales (Log Scale)',
yaxis_title='Frequency',
title='Sales Distribution',
xaxis_title_font=dict(size=14),
yaxis_title_font=dict(size=14),
title_font=dict(size=18),
xaxis_showgrid=True,
yaxis_showgrid=True,
xaxis_gridcolor='gray',
yaxis_gridcolor='gray',
# Set the background color to a darker shade
paper_bgcolor='rgba(50, 50, 50, 1)', # Background outside the plot area
plot_bgcolor='rgba(40, 40, 40, 1)', # Background inside the plot area
# Customize font colors to ensure readability on a dark background
font=dict(color='white')
)
# Show the plot
fig1.show()