0

I want to fill a custom plot similar to what a bar chart does. In the minimum working example below I want to fill e.g. the rectangular "x1=1.2 y1=till top, x2=till end, y2=till top". Unfortunately the below code renders not as expected (see picture). Any ideas?

import numpy as np
import matplotlib.pyplot as plt

def plot():
    fig, ax = plt.subplots(1, 1)

    # X, Y - POLYGON
    c_x = [0,
           0,
           2,
           3,
           4,
           4
           ]
    c_y = [0,
           2,
           2,
           2,
           2,
           0
           ]

    x_1 = np.array(c_x)
    y_1 = np.array(c_y)

    ax.plot(x_1, y_1, color='black')
    ax.fill_betweenx(y_1, x_1, y_1, where=(x_1 > 1.2), interpolate=True)

    ax.axis('equal')

    plt.show()
    
plot()

Unfortunately the code renders like this... enter image description here

  • Can you explain what you *want* the image to look like? – ShlomiF Nov 21 '22 at 09:30
  • 1
    `fill_between` only supports breaking the x-values at the original x-values. `interpolate=True` only addressees the y-values. You'd need a much more fine-grained x-axis to accomplish what you seem to expect. – JohanC Nov 21 '22 at 10:20

0 Answers0