python - matplotlib tick axis notation with superscript -
i produce plot on frequencies. want have x-axis superscript notation in here. in addition need vertical lines vertical annotation separate kilo , mega hz.
import numpy np import matplotlib.pyplot 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') plt.legend() plt.show()
i tried use ticker can't figure out how set it. tried follow some examples got error attributeerror: 'figure' object has no attribute 'ticklabel_format'
spend quite lot of time on , don't know how move forward.
in general need x-axis formatted in similar way, if plt.xscale('log')
want keep linear scale.
you can define tick-marks strings , assign those:
mport numpy np import matplotlib.pyplot 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 = [] 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()
Comments
Post a Comment