python - Formatting axes when plotting with matplotlib -


I am trying to format the X-axis of the plot generated by the following sample code. The X-axis log plot is currently plotted, in the plot, the [1000,2000,3000,4000,5000] shows with minor tics = 100. I want to see every 100 as the key feature of the label from [0,1000]. and then [1000,5000] only every 1000

Actually, I want the X-axis to have the following labels: [100,200,300,400,500,600,700,800,900, 10002000,3000,4000,5000] . Is it possible to use matplotlib?

  import matplotlib import from imported math import matplotlib.ticker import from Palplot multiple multiplexes, FormatStrFormatter ### ------------- ------ ---------- ### plot_aspect = 1.7 plot_height = 10.0 plot_width = int (plot_height * plot_aspect) pyplot.figure (fig = = (plot_width, plot_height), dPI = 100) Paplot .subplots_adjust (left = 0.10, right = 0.90, top = 0.90, bottom = 0.10, HSPS = 0.30) ### ----------------------- ------ ### Title1 = 'Example Plot Title' main_title = 'Example Main Title' png_title = 'example_plot.png' file1_data = [] For category (10,5100,10): b = (60- (2 * math.log (i))) + Remember Chchik. Uniform (-2.0,2.0) file1_data.append ([i, b]) # ---------- subplot1 = pyplot.subplot (111) MajorLocator1 = multiple Leketr (1000) majorFormatter1 = FormatStrFormatter ( '% d ') Minorocator 1 = multiple lacquer (100) pyplot.plot (numpy.array (file1_data) [,, 0], numpy.array (file1_data) [,, 1],' red ', linewidth = 1.0, label = title 1 ) Pyplotkxscale ( 'log', Fontisejh = 10) Paplotkksail (0,5000) Paplotkksksiks (Fonsetijh = 10) Sbplot 1. Aksaks_set_mjr_laoketr (major Leketr 1) Sbplot 1. Aksaksiskset_mjr_formr (Pramukformr 1) Sbplot 1 Xxis Et_mnir_loketr (Lguloketr 1) Sbplot 1. Ksaksiskgrid () Peeplotklijend (Public = 3, Prop = { "size": 20}) Peeplotkytikks (Fontsize = 16) Peeplotkilim (30,65) Peeplotkshlbel ( 'Frank [Hajj], Font size = 16, weight = "bold") pipette. Label ('PSD (db / hj)', font size = 16, weight = "bold") pipette. Superficial (main-title, font size = 28, weight = "bold") ###--------------------------- ## # Pyplot.savefig (png_title, dpi = 100) pyplot.show ()  

<P

@tahbout has given me this one (with some minor adjustments) Help in:

  import dimensional imports import import random matplotlib import matplotlib.ticker import from Plotot multiple lectures, FormatStrFormatter ### -------------- --------------- ### plot_height = 10.0 plot_width = int (plot_height * plot_aspect) pyplot.figure (figsize = (plot_width, plot_heig Ht), dpi = 100) pyplot.subplots_adjust (left = 0.10, right = 0.90, top = 0.90, bottom = 0.10, hspace = 0.30) ### ---------------- ------------- ### Title 1 = 'Example Plot Title' main_title = 'Example Main Title' png_title = 'example_plot.png' file1_data = [] Category (10,5100,10 ) In: b = (60- (2 * math.log (i))) + Random.uniform (-2.0,2.0) file1_data.append ([i, b]) # ---------- subplot1 = pyplot.subplot (111) majorLocator1 = multiple Leketr (1000) majorFormatter1 = FormatStrFormatter ( '% D') Alploketr 1 = multiple Leketr (100) Paipotkplot (numpy.array (file1_data) [,, 0], numpy. Array (file1_data) [, 1], 'red', linewidth = 1.0, label = title1) Pyplot.xscale ('logs', fontsis = 10) pyplot.xlim (0,5000) xticks = Category (100, 1001, 100) + Series (2000, 6000, 1000) # pyplot.xticks (fontsize = 10) Paplot Xticks (xticks, fontsize = 10) # subplot1.xaxis.set_major_locator (major Lesretr 1) Subplot1.xaxis. Set_major_formatter (majorFormatter1) # subplot1.xaxis.set_minor_locator (shortcut 1) subplot1.xaxis.grid () pyplot.legend (loc = 3, prop = {'size': 20}) pyplot.yticks (fontsize = 16) Pyplot.ylim (30,65) pyplot.xlabel ('Freq [Hz]', font size = 16, weight = "bold") pipette. Label ('PSD [db / hj]', font size = 16, weight = "bold") Pyplot .suptitle (main-title, font size = 28, weight = "bold") ### ----------------------------- # ## pyplot.savefig (png_title, dpi = 100) pyplot.show ()  


Comments