Square root scale using matplotlib/python

后端 未结 4 1773
孤独总比滥情好
孤独总比滥情好 2020-12-21 05:55

I want to make a plot with square root scale using Python:

However, I have no idea how to make it. Matplotlib allows to make log scale but in this case I ne

4条回答
  •  孤城傲影
    2020-12-21 06:20

    This a simple way to graph sqrt(x)

    import numpy as np
    from matplotlib import pyplot as plt
    
    plt.rcParams["figure.dpi"] = 140
    
    fig, ax = plt.subplots()
    ax.spines["left"].set_position("zero")
    ax.spines["bottom"].set_position("zero")
    ax.spines["right"].set_color("none")
    ax.spines["top"].set_color("none")
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    
    origin = [0, 0]
    
    # 45
    plt.plot(
        np.linspace(0, 1, 1000),
        np.sqrt(np.linspace(0, 1, 1000)),
        color="k",
    )
    
    ax.set_aspect("equal")
    plt.xlim(-0.25, 1)
    plt.ylim(0, 1)
    plt.yticks(ticks=np.linspace(0, 1, 6))
    plt.show()
    

提交回复
热议问题