Skip to content
Snippets Groups Projects
Commit e87ccee2 authored by Marius Heidenreich's avatar Marius Heidenreich
Browse files

Delete test2.py

parent 38c41fc3
No related branches found
No related tags found
No related merge requests found
Pipeline #277542 passed
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.patches as patches
# Create custom colormap
colors = [(255/255, 255/255, 30/255), (255/255, 196/255, 0/255)] # RGB values for #ffff1e and #ffc400
custom_yellow_cmap = LinearSegmentedColormap.from_list('custom_yellow', colors)
np.random.seed(19680801)
# Create figure directly without subplot
fig = plt.figure(figsize=(8, 6))
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # [left, bottom, width, height]
N = 10
y = np.arange(N)
x = np.random.rand(N)
# Create horizontal bars
bars = ax.barh(y, x, height=0.7)
# Apply gradient to each bar
for bar in bars:
# Get the coordinates of the bar
x0, y0 = bar.get_xy()
width = bar.get_width()
height = bar.get_height()
# Set the bar's face color to none (remove default color)
bar.set_facecolor('none')
# Create multiple thin rectangles to simulate a gradient
steps = 50
for i in range(steps):
left = x0 + (i/steps) * width
rect_width = width/steps
color = custom_yellow_cmap(i/steps)
rect = patches.Rectangle((left, y0), rect_width, height,
linewidth=0,
color=color)
ax.add_patch(rect)
# Set limits and labels
ax.set_xlim(0, 1)
ax.set_ylim(-0.5, N-0.5)
ax.set_title('Horizontal Bar Chart with Yellow Gradient')
ax.set_xlabel('Values')
ax.set_ylabel('Categories')
plt.show()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment