To add a secondary x-axis that shows minutes instead of seconds in matplotlib, you can use the twinx
function to create a secondary y-axis and then set the ticks and labels of the secondary x-axis to display minutes instead of seconds. Here's an example:
main.py681 chars28 lines
In this example, the primary x-axis shows the time in seconds, and the secondary x-axis shows the time in minutes. The ax1.twiny()
function creates a secondary x-axis that shares the same y-axis as the primary x-axis (ax1
). The tick values and labels for the secondary x-axis are set using the set_xticks
and set_xticklabels
methods. The tick values are converted from seconds to minutes using numpy operations, and the tick labels are formatted as minutes:seconds using a list comprehension.
Hope this helps!
gistlibby LogSnag