matplotlib tick axis notation with superscript

后端 未结 2 1956
离开以前
离开以前 2020-12-11 10:59

I would like to produce some plot over the frequencies. I want to have an x-axis with superscript notation like in here. In addition I need vertical lines with vertical ann

相关标签:
2条回答
  • 2020-12-11 11:35

    You can define the tick-marks as strings and assign those:

    mport numpy as np
    import matplotlib.pyplot as plt
    band = np.linspace(0,10**12,100)
    y = band
    
    plt.plot(band,y)
    plt.xlabel("Frequencies")
    
    plt.vlines(10**3, min(y), max(y),colors = 'black', label = 'kilo Hz')
    plt.vlines(10**6, min(y), max(y),colors = 'black', label = 'mega Hz')
    
    string_labels = []
    for i in range(0,len(y),10):
        string_labels.append(r"$10^{%02d}$" % (i/10.0))
    
    plt.xticks(np.linspace(0,10**12,10),string_labels)
    
    plt.legend()
    plt.show()
    
    0 讨论(0)
  • 2020-12-11 11:50

    I'm just shooting in the dark, but looks like xlabel takes a variety of options:

    http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel

    When I went to:

    http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text

    I noticed that there is a verticalalignment option. Maybe that's what you need?

    0 讨论(0)
提交回复
热议问题