reworked logic pivot study matplot lib