Square root scale using matplotlib/python

后端 未结 4 1740
孤独总比滥情好
孤独总比滥情好 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:00

    I like lolopop's comment and tom's answer, a more quick and dirty solution would be using set_yticks and set_yticklabels as in the following:

    x = np.arange(2, 15, 2)
    y = x * x
    
    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122)
    
    ax1.plot(x,y)
    
    ax2.plot(x, np.sqrt(y))
    ax2.set_yticks([2,4,6,8,10,12,14])
    ax2.set_yticklabels(['4','16','36','64','100','144','196'])
    

提交回复
热议问题