Python/Matplotlib - Is there a way to make a discontinuous axis?

后端 未结 5 694
春和景丽
春和景丽 2020-11-22 07:46

I\'m trying to create a plot using pyplot that has a discontinuous x-axis. The usual way this is drawn is that the axis will have something like this:

(values)----/

5条回答
  •  暖寄归人
    2020-11-22 08:10

    Check the brokenaxes package:

    import matplotlib.pyplot as plt
    from brokenaxes import brokenaxes
    import numpy as np
    
    fig = plt.figure(figsize=(5,2))
    bax = brokenaxes(xlims=((0, .1), (.4, .7)), ylims=((-1, .7), (.79, 1)), hspace=.05)
    x = np.linspace(0, 1, 100)
    bax.plot(x, np.sin(10 * x), label='sin')
    bax.plot(x, np.cos(10 * x), label='cos')
    bax.legend(loc=3)
    bax.set_xlabel('time')
    bax.set_ylabel('value')
    

提交回复
热议问题