Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when adding matrix in the X-axis #4742

Closed
bestmoon opened this issue Jul 18, 2015 · 7 comments
Closed

Error when adding matrix in the X-axis #4742

bestmoon opened this issue Jul 18, 2015 · 7 comments

Comments

@bestmoon
Copy link

using the matplotlib 1.3.1, the error message:

File "bar-chart.py", line 68, in plot
    plt.tight_layout()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 1255, in tight_layout
    fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1607, in tight_layout
    self.subplots_adjust(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 1467, in subplots_adjust
    self.subplotpars.update(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.3.1-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 217, in update
    raise ValueError('left cannot be >= right')
ValueError: left cannot be >= right

The source code is

ind_label = [
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right) $',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$'
    ]

Thanks a lot for your help.

@efiring
Copy link
Member

efiring commented Jul 18, 2015

Please provide a minimal but complete, standalone example that triggers the error. It looks to me like it is not directly related to the ind_label array of strings that you show.

@bestmoon
Copy link
Author

The code follows. It should be runnable.


#!/bin/python

import sys
import numpy as np
import math
import decimal 
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab 
from matplotlib import rcParams

def plot():

    rcParams['text.usetex'] = True

    N = 6
    ind = np.arange(N)
    ind_label = [
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right) $',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$',
    r'$ \left(\begin{array}{ccc} a & b & c \\ d & e & f \\ g & h & i \end{array} \right)$'
    ]

    y = [1.60, 1.65, 1.70, 1.75, 1.80]
    n_b = [1.747, 1.747, 1.747, 1.746, 1.746, 1.746]
    b_n = [1.746, 1.737, 1.742, 1.783, 1.780, 1.790]
    svm = [1.689, 1.694, 1.702, 1.639, 1.634, 1.628]

    width = 0.2

    fig = plt.figure()
    ax = fig.add_subplot(111)

    rec_nb  = ax.bar(ind, n_b, width, color='c', align='center')
    rec_bn  = ax.bar(ind+width, b_n, width, color='y', align='center')
    rec_svm = ax.bar(ind+width*2, svm, width, color='b', align='center')

    ax.set_ylabel('Value',fontsize=20)
    ax.set_xlabel('Matrix', fontsize=20)
    ax.tick_params(axis='both', labelsize=17)
    ax.set_xticks(ind+width)
    ax.set_xticklabels(ind_label, fontsize=18)
    ax.axis([-0.2, 5.6, 1.58, 1.82])

    ax.legend((rec_nb[0],rec_bn[0],rec_svm[0]),('method 1','method 2','method 3'), loc="upper right",shadow=True)

    plt.grid()
    plt.tight_layout()
    plt.show()


if __name__ == '__main__':
    plot()

The expected output is:
figure_1

The error is reproducible on my host.
The message says:

Traceback (most recent call last):
  File "bar-example.py", line 55, in <module>
    plot()
  File "bar-example.py", line 50, in plot
    plt.tight_layout()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 1288, in tight_layout
    fig.tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1665, in tight_layout
    self.subplots_adjust(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1522, in subplots_adjust
    self.subplotpars.update(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 221, in update
    raise ValueError('left cannot be >= right')

Thanks a lot for your time and help.

@efiring
Copy link
Member

efiring commented Jul 19, 2015

I can't reproduce it on either 1.3.1 or on master; I get exactly your expected output, with no Exception being raised. Maybe you have a custom matplotlibrc, and the difference is in an rcParams setting? Does it work for you if you comment out the tight_layout call?

@bestmoon
Copy link
Author

Then, it is so wired. I use pip and easy_install to install the matplotlib. Both give me this type of error.

As you suggested, I comment out the tight_layout(). And, the figure was plotted without labelings on x-axis and y-axis.
The error messgae says:

$ python bar-example.py
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.py", line 338, in resizeEvent
    self.draw()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5agg.py", line 148, in draw
    FigureCanvasAgg.draw(self)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 469, in draw
    self.figure.draw(self.renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1085, in draw
    func(*args)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2110, in draw
    a.draw(renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1128, in draw
    self.label.draw(renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 59, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/text.py", line 638, in draw
    self._fontproperties, angle, mtext=mtext)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 259, in draw_tex
    self._renderer.draw_text_image(Z, x, y, angle, gc)
ValueError: cannot convert float NaN to integer

Does that mean something?
Thanks a lot for your prompt reply.

@efiring
Copy link
Member

efiring commented Jul 19, 2015

So even without tight_layout, you are getting an obscure error. I am wondering whether the problem is in your latex installation. Can you run the usetex_demo.py? http://matplotlib.org/examples/pylab_examples/usetex_demo.html

@bestmoon
Copy link
Author

Actually, I have no problem to run the usetex_demo.py code.
The result matches the provided one. There is no error.

figure_1

And, as you suggested, I am also doubt the problem is in the latex installation.
I reinstalled it using the following scripts.

sudo apt-get update
sudo apt-get install texlive-full
sudo apt-get install gedit-latex-plugin texlive-fonts-recommended latex-beamer texpower texlive-pictures texlive-latex-extra

The problem is still there :(
Anyway, I found a clean host and reinstalled matplotlib. It works well as I expected.

Thanks a lot for all your help.

@efiring
Copy link
Member

efiring commented Jul 20, 2015

Glad you solved the problem.

@efiring efiring closed this as completed Jul 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants