static large graph

This commit is contained in:
2023-10-17 18:30:41 +03:00
parent 36b5b92a97
commit 821087138a

View File

@@ -1,6 +1,6 @@
import pandas as pd import pandas as pd
import plotly.express as px import matplotlib.pyplot as plt
import plotly.graph_objects as go import numpy as np
# Read the CSV file into a Pandas DataFrame # Read the CSV file into a Pandas DataFrame
file_path = "texts_by_period_and_location_saparated_by_periods_in_columns.csv" file_path = "texts_by_period_and_location_saparated_by_periods_in_columns.csv"
@@ -12,21 +12,24 @@ columns_to_summarize = ["ancient", "old", "middle", "new", "late"]
# Group the data by the "place" column and calculate sums within each group # Group the data by the "place" column and calculate sums within each group
grouped = df.groupby("place")[columns_to_summarize].sum().reset_index() grouped = df.groupby("place")[columns_to_summarize].sum().reset_index()
# Create a bar chart using Plotly # Create a list of colors for the inner divisions
fig = go.Figure() colors = ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd"]
# Add a bar trace for each category # Create the figure and axis for the bar chart
for col in columns_to_summarize: fig, ax = plt.subplots()
fig.add_trace(go.Bar(x=grouped["place"], y=grouped[col], name=col))
# Customize the layout # Create bars for each place with inner divisions
fig.update_layout( bottom = np.zeros(len(grouped))
title="Summary of Categories by Place with Filtering", for i, col in enumerate(columns_to_summarize):
xaxis_title="Place", ax.bar(grouped["place"], grouped[col], 0.6, bottom=bottom, color=colors[i], label=col)
yaxis_title="Total Count", bottom += grouped[col]
xaxis=dict(categoryorder='total descending'),
barmode='group'
)
# Show the interactive graph # Customize the plot
fig.show() ax.set_ylabel("Total Count")
ax.set_title("Summary of Categories by Place with Inner Divisions")
ax.set_xticks(np.arange(len(grouped["place"])))
ax.set_xticklabels(grouped["place"], rotation=45, ha="right")
ax.legend(loc='upper right')
# Display the plot
plt.show()