Backport PR #6587 : Support %matplotlib qt5 and %matplotlib nbagg