Spaces:
Sleeping
Sleeping
File size: 1,547 Bytes
b07caec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# ===================
# Part 1: Importing Libraries
# ===================
import matplotlib.pyplot as plt
# ===================
# Part 2: Data Preparation
# ===================
# Data for plotting
categories = ["0-9", "10-19", "20-29", "30-39", "40-49"]
values = [0.60, -0.55, -0.76, -0.80, -0.85]
# Plot configuration variables
ylabel = "spearman"
xlabel = "length"
xlim = (-0.5, 4.5)
ylim = (-1, 0.75)
yticks = [-1.00, -0.75, -0.5, -0.25, 0, 0.25, 0.50, 0.75]
# ===================
# Part 3: Plot Configuration and Rendering
# ===================
# Create the figure and the bar chart
fig, ax = plt.subplots(figsize=(6, 6))
bars = ax.bar(categories, values, color="#44739d", edgecolor="white", width=1, zorder=3)
# Set labels and title
ax.set_ylabel(ylabel)
ax.set_xlabel(xlabel)
ax.set_xlim(xlim)
ax.set_ylim(ylim)
ax.tick_params(axis="y", which="both", length=0)
ax.tick_params(axis="x", which="both", length=0)
ax.set_yticks(yticks)
ax.set_facecolor("#eaeaf2") # Set the axes background color
ax.yaxis.grid(True, color="white", zorder=2) # Add grid lines
# Remove the border around the chart area
for spine in ax.spines.values():
spine.set_visible(False)
# Ensure that the bars for negative values start from zero
for bar in bars:
if bar.get_height() < 0:
bar.set_y(0)
# Add padding around the chart
plt.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
# ===================
# Part 4: Saving Output
# ===================
# Show the plot
plt.tight_layout()
plt.savefig("bar_11.pdf", bbox_inches="tight")
|