python - How to setup the same scale for X axis (timestamp) in multiple graphs using matplotlib -
i using python
, matplotlib
try generate following: 4 charts plotting amount of messages received in system vs delay in processing these messages, in given period of time, in intervals of 5 minutes.
that is, x
axis shows time moment a
moment b
(in format "%y-%m-%d %h:%m
") in intervals of 5 minutes, while left y
axis shows amount of messages received @ given moment, , right y
axis shows delays in processing these messages.
now, got plotting both x
axes in chart, need timestamps same every graph, is, must start , end @ same point in time, if there no events in times of charts (e.g., chart#1 starts @ 15:50 of 10/5/2015 , stopped @ 14:00 11/5/2015, if in 1 of them events start happening @ 17:00 of 10/5). , that's killer.
does know how can this? lot
does know how can this?
yes.
if stack overflow allow non-mcve posts in questions, simplistic answers, saying "yes", spring off box, bring no real experience great community stackoverflow undoubtedly is.
think while & point. way no 1 appreciate.
q: how...?
you may re-use of formatting tricks. might have experienced, matplotlib
's complex structure sort-of sensitive, formatting takes place in figure
processing. things work "before" plotting data, "after" plotting data-points/lines. not hesitate test/reorder sections & feel wish have within reasonable time spent on these polishing touches ( real-value typically in data-related insights & phenomena-related experience converted new, strategic value called knowlege, isn't it? ).
so few cents:
#---------------------------------------------------- # x-axis formatting aplotax.set_xlim( x_min, x_max ) # x-axis limits --- #lt.gca().xaxis.set_major_locator( matplotlib.ticker.fixedlocator( secs ) ) #lt.gca().xaxis.set_major_formatter( matplotlib.ticker.funcformatter( lambda pos, _: time.strftime( "%d-%m-%y %h:%m:%s", time.localtime( pos ) ) ) ) aplotax.xaxis.set_major_locator( autodatelocator() ) aplotax.xaxis.set_minor_locator( hourlocator() ) #plotax.xaxis.set_minor_locator( minutelocator() ) # if not dense aplotax.xaxis.set_major_formatter( dateformatter( '%y-%m-%d %h:%m' ) ) # -------------------------------------------------------------------- x-format #----------------------------------------------- # 90-deg x-tick-labels try: plt.setp( plt.gca().get_xticklabels(), rotation = 90, horizontalalignment = 'right' ) except: print "debug: exc() on plt.setp( plt.gca().get_xticklabels(), rotation = 90, ... )" # --------------------------------------------- # "tight"-en layout try: plt.tight_layout() except: print "debug: exc() on plt.tight_layout()" ''' pre-save_as-configuration(s) ||||||||||||||||||||||||||||||||||||||||||||| #fig.set_figwidth( 1600.0 ) #fig.set_figheight( 1400.0 ) # facecolor = 'k', # inverse colourscheme # edgecolor = 'w', afig = plt.figure( figsize = ( 5, 5 ), dpi = 100 ) # size not in [inch], in [spatial-units] 100-px-each... #lt .savefig( <afilename.png>, transparent = true, dpi = 300 ) # .png alpha-channel background std-[px]-size 800x600 @ dpi #lt .savefig( <afilename.svg>, transparent = true, dpi = 300 ) # .svg alpha-channel background std-[px]-size 800x600 @ dpi #lt .savefig( <afilename.000>, transparent = true, dpi = 300, format = "svg" ) # .svg alpha-channel background std-[px]-size 800x600 @ dpi #lt .savefig( <afilename.pdf>, transparent = true, dpi = 300 ) # .pdf alpha-channel background std-[px]-size 800x600 @ dpi # matplotlib.backends.backend_pdf import pdfpages # .pdf-multi-page document # pdf_pages = pdfpages('barcharts.pdf') # afig = plt.figure... # plt.plot... # pdf_pages.savefig( afig ) # .closes apdfpage # ...plot # pdf_pages.savefig( afig ) # .closes apdfpage # pdf_pages.close() # finally: fileio on disk
Comments
Post a Comment