1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Only colour part of axis in matplotlib

Discussão em 'Python' iniciado por Stack, Outubro 8, 2024.

  1. Stack

    Stack Membro Participativo

    Consider the simple plot

    import matplotlib.pyplot as plt

    x = [0.9, 1, 1.1, 1.2, 1.3]
    y = [0, 0.1, 0.3, 0.6, 1]

    plt.plot(x,y)

    plt.margins(x=0, y=0)
    plt.xlim(0,3)


    This generates a line plot. From here I would like to colour part of my x-axis such that from 0 to 0.9 is blue and from 0.9 to 3 is red. One solution I came up with is include two more line plots: plt.plot([0,0.9], [0,0], color = "b" ,linewidth=3.0) and plt.plot([0.9,3.0], [0,0], color = "r",linewidth=3.0). Giving the following picture: [​IMG] This looks okay, but I'm not entirely happy with it. To me it is clear that those lines are not on the axis, but rather slightly above the axis. Instead I would prefer to have the axis + ticks take on the respective colour.

    Continue reading...

Compartilhe esta Página