Reputation: 56
I have two measures which I want to show as horizontal overlapping bar graph with both the ends curved and white border. Something similar to the image.
import matplotlib.pyplot as plt
import numpy as np
# Sample data
Val1 = [52]
Val2 = [100]
# Width of the bars
bar_width = 0.4
# Create the figure and axis
fig, ax = plt.subplots(figsize=(8, 2))
# Plot the bars
ax.barh(0, Val1, height=0.2,
color='lightblue',
edgecolor='white', label='Val1', alpha=0.7)
ax.barh(0, Val2, height=0.2, color='blue', edgecolor='none', label='Val2', alpha=1)
# Add rounded corners using patches
for bar in ax.patches:
bar.set_linewidth(0)
bar.set_capstyle('round')
# Add labels and formatting
ax.set_yticks([])
ax.set_xticks([0, Val1[0]])
ax.set_xlim(0, Val1[0] + 100)
ax.legend(loc='upper right')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_visible(False)
# Show plot
plt.tight_layout()
plt.show()
This is giving me the overlapping bars but not the curved ends. How can I get the curved ends.
The input is two values [Val1], [Val2].
Upvotes: 0
Views: 20