Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-964

Python 3.7 crashes after import matplotlib after PySide2

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.12.1
    • PySide
    • None
    • Windows 7 64-bit version and PySide2 5.12.1
    • Windows

    Description

      Trying to plot graphs with matplotlib and PySide2 I wrote the following code:

       

      from PySide2 import QtWidgets, QtCore, QtGui
      import numpy as np
      import matplotlib.pyplot as plt
      
      men_means, men_std = (20, 35, 30, 35, 27), (2, 3, 4, 1, 2)
      women_means, women_std = (25, 32, 34, 20, 25), (3, 5, 2, 3, 3)
      
      ind = np.arange(len(men_means)) # the x locations for the groups
      width = 0.35 # the width of the bars
      
      fig, ax = plt.subplots()
      rects1 = ax.bar(ind - width/2, men_means, width, yerr=men_std,
       color='SkyBlue', label='Men')
      rects2 = ax.bar(ind + width/2, women_means, width, yerr=women_std,
       color='IndianRed', label='Women')
      
      # Add some text for labels, title and custom x-axis tick labels, etc.
      ax.set_ylabel('Scores')
      ax.set_title('Scores by group and gender')
      ax.set_xticks(ind)
      ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5'))
      ax.legend()
      
      
      def autolabel(rects, xpos='center'):
       """
       Attach a text label above each bar in *rects*, displaying its height.
      
       *xpos* indicates which side to place the text w.r.t. the center of
       the bar. It can be one of the following {'center', 'right', 'left'}.
       """
      
       xpos = xpos.lower() # normalize the case of the parameter
       ha = {'center': 'center', 'right': 'left', 'left': 'right'}
       offset = {'center': 0.5, 'right': 0.57, 'left': 0.43} # x_txt = x + w*off
      
       for rect in rects:
       height = rect.get_height()
       ax.text(rect.get_x() + rect.get_width()*offset[xpos], 1.01*height,
       '{}'.format(height), ha=ha[xpos], va='bottom')
      
      
      autolabel(rects1, "left")
      autolabel(rects2, "right")
      
      plt.show()
      
      
      

      The problem is that the Python crashes every time I ran the code. The problem stops when I comment the PySide2 import. I'm using 

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            piontk TIAGO PIONTEWICZ
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes