erro python em execução matplotlib pyplot

votos
0

Estou tentando executar código python, mas tem problemas tornando uma figura (ele consegue traçar a curva, mas não consegue adicionar eixo e etiquetas etc) e começa a produzir um fluxo de erros. Eu estou usando uma máquina de 64 bits do Windows 7 com Python (x, y) e o fluxo de erro parecido com este:

Além disso, a corrente abaixo de erro é produzido com IDLE

mas

se eu executá-lo através Spyder, o terminal cospe um erro diferente: WindowsError: [Error 2] The system cannot find the file specified.

Traceback (most recent call last):

  File C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4.py, line 299, in resizeEvent
    self.draw()
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4agg.py, line 154, in draw
    FigureCanvasAgg.draw(self)
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py, line 451, in draw
    self.figure.draw(self.renderer)
  File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File C:\Python27\lib\site-packages\matplotlib\figure.py, line 1034, in draw
    func(*args)
  File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File C:\Python27\lib\site-packages\matplotlib\axes.py, line 2086, in draw
    a.draw(renderer)
  File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File C:\Python27\lib\site-packages\matplotlib\axis.py, line 1093, in draw
    renderer)
  File C:\Python27\lib\site-packages\matplotlib\axis.py, line 1042, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File C:\Python27\lib\site-packages\matplotlib\text.py, line 754, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File C:\Python27\lib\site-packages\matplotlib\text.py, line 320, in _get_layout
    ismath=False)
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py, line 205, in get_text_width_height_descent
    renderer=self)
  File C:\Python27\lib\site-packages\matplotlib\texmanager.py, line 669, in get_text_width_height_descent
    page = next(iter(dvi))
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 85, in __iter__
    have_page = self._read()
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 146, in _read
    self._dispatch(byte)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 234, in _dispatch
    self._fnt_def(k, c, s, d, a, l, n)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 394, in _fnt_def
    tfm = _tfmfile(n[-l:].decode('ascii'))
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 901, in _tfmfile
    return _fontfile(texname, Tfm, '.tfm', _tfmcache)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 891, in _fontfile
    filename = find_tex_file(texname + suffix)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 872, in find_tex_file
    stderr=subprocess.PIPE)
  File C:\Python27\lib\subprocess.py, line 701, in __init__
    errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
  File C:\Python27\lib\subprocess.py, line 832, in _get_handles
    p2cread = self._make_inheritable(p2cread)
  File C:\Python27\lib\subprocess.py, line 883, in _make_inheritable
    _subprocess.DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid
Traceback (most recent call last):
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4.py, line 299, in resizeEvent
    self.draw()
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_qt4agg.py, line 154, in draw
    FigureCanvasAgg.draw(self)
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py, line 451, in draw
    self.figure.draw(self.renderer)
  File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File C:\Python27\lib\site-packages\matplotlib\figure.py, line 1034, in draw
    func(*args)
  File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File C:\Python27\lib\site-packages\matplotlib\axes.py, line 2086, in draw
    a.draw(renderer)
  File C:\Python27\lib\site-packages\matplotlib\artist.py, line 55, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File C:\Python27\lib\site-packages\matplotlib\axis.py, line 1093, in draw
    renderer)
  File C:\Python27\lib\site-packages\matplotlib\axis.py, line 1042, in _get_tick_bboxes
    extent = tick.label1.get_window_extent(renderer)
  File C:\Python27\lib\site-packages\matplotlib\text.py, line 754, in get_window_extent
    bbox, info, descent = self._get_layout(self._renderer)
  File C:\Python27\lib\site-packages\matplotlib\text.py, line 320, in _get_layout
    ismath=False)
  File C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py, line 205, in get_text_width_height_descent
    renderer=self)
  File C:\Python27\lib\site-packages\matplotlib\texmanager.py, line 669, in get_text_width_height_descent
    page = next(iter(dvi))
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 85, in __iter__
    have_page = self._read()
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 146, in _read
    self._dispatch(byte)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 234, in _dispatch
    self._fnt_def(k, c, s, d, a, l, n)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 394, in _fnt_def
    tfm = _tfmfile(n[-l:].decode('ascii'))
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 901, in _tfmfile
    return _fontfile(texname, Tfm, '.tfm', _tfmcache)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 891, in _fontfile
    filename = find_tex_file(texname + suffix)
  File C:\Python27\lib\site-packages\matplotlib\dviread.py, line 872, in find_tex_file
    stderr=subprocess.PIPE)
  File C:\Python27\lib\subprocess.py, line 701, in __init__
    errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
  File C:\Python27\lib\subprocess.py, line 832, in _get_handles
    p2cread = self._make_inheritable(p2cread)
  File C:\Python27\lib\subprocess.py, line 883, in _make_inheritable
    _subprocess.DUPLICATE_SAME_ACCESS)
WindowsError: [Error 6] The handle is invalid

Adicionando o meu código fonte ... é a última linha que está criando um problema.

Eu tenho LaTeX instalado através texniccentermas eu não tenho certeza de como modificar as configurações para fazer o trabalho com este código (desculpe, eu sou novo para isso!).

from cvxpy import *
import numpy
import matplotlib.pyplot as plt
from matplotlib import rcParams

# Problem data.
numpy.random.seed(1)

PGRIDMAX = 1000 #kw
PPVCAP = 200 #kw
PLOADPEAK = 500 #kw
PRICEMAX = .5 #$/kwh

QBATTCAP = 1000 #kwh
PBATTCAP = 500 #kw
QMIN = 0.2 #DOD
QMAX = 0.9 #DOD
ETAQ = 0.9 #storage efficiency
ETAP = 0.85 #charging efficiency

nt = 20
PPVMAX = -PPVCAP*numpy.random.random(nt)
PLOADMAX = PLOADPEAK*numpy.random.random(nt)
PRICE = PRICEMAX*numpy.random.randn(nt)


# Construct the problem.
pgrid = Variable(nt)
pload = Variable(nt)
ppv = Variable(nt)
pbatt = Variable(nt)
qbatt = Variable(nt)

objective = Minimize(sum_squares(mul_elemwise(PRICE,pgrid)))
constraints = [pgrid == pload + ppv + pbatt, abs(pgrid) <= PGRIDMAX,
               PPVMAX <= ppv, ppv <= 0,
               0 <= pload, pload <= PLOADMAX,
               qbatt[1:] == ETAQ*qbatt[:nt-1] + ETAP*pbatt[:nt-1],
               QMIN*QBATTCAP <= qbatt, qbatt <= QMAX*QBATTCAP,
               -PBATTCAP <= pbatt, pbatt <= PBATTCAP
               ]

prob = Problem(objective, constraints)

# The optimal objective is returned by prob.solve().
result = prob.solve(solver=CVXOPT)
# The optimal value for x is stored in x.value.
print pgrid.value
# The optimal Lagrange multiplier for a constraint
# is stored in constraint.dual_value.
# print constraints[0].dual_value
print status:, prob.status
print optimal value, prob.value



# Show plot inline in ipython.
#%matplotlib inline

# Plot properties.
plt.rc('text', usetex=True)
plt.rc('font', family='serif')

#
# First Figure:
#
#plt.figure(figsize=(6, 6))
#plt.scatter(np.array(loc[:, 0]), np.array(loc[:, 1]), \
#            s=30, facecolors='none', edgecolors='b')
#plt.title('Antenna Locations', fontsize=16)
#plt.tight_layout()
#plt.show()

#
# Second Plot:
ppvarray = numpy.bmat(ppv.value)
pgridarray = numpy.bmat(pgrid.value)

plt.figure(figsize=(6,6))
#ymin, ymax = -40, 0
plt.plot(numpy.arange(nt), numpy.array(numpy.abs(pgridarray)), 'b-')
plt.xlabel('time', fontsize=16)
plt.ylabel('$P__P_V$ in kWh', fontsize=16)
#plt.ylim(ymin, ymax)

#plt.tight_layout()
plt.show()

rcParams saída:

agg.path.chunksize: 0
animation.avconv_args: 
animation.avconv_path: avconv
animation.bitrate: -1
animation.codec: mpeg4
animation.convert_args: 
animation.convert_path: convert
animation.ffmpeg_args: 
animation.ffmpeg_path: ffmpeg
animation.frame_format: png
animation.mencoder_args: 
animation.mencoder_path: mencoder
animation.writer: ffmpeg
axes.axisbelow: False
axes.color_cycle: ['b', 'g', 'r', 'c', 'm', 'y', 'k']
axes.edgecolor: k
axes.facecolor: w
axes.formatter.limits: [-7, 7]
axes.formatter.use_locale: False
axes.formatter.use_mathtext: False
axes.grid: False
axes.hold: True
axes.labelcolor: k
axes.labelsize: medium
axes.labelweight: normal
axes.linewidth: 1.0
axes.titlesize: large
axes.unicode_minus: True
axes.xmargin: 0
axes.ymargin: 0
axes3d.grid: True
backend: Qt4Agg
backend.qt4: PyQt4
backend_fallback: True
contour.negative_linestyle: dashed
datapath: C:\Python27\lib\site-packages\matplotlib\mpl-data
docstring.hardcopy: False
examples.directory: 
figure.autolayout: False
figure.dpi: 80
figure.edgecolor: w
figure.facecolor: 0.75
figure.figsize: [8.0, 6.0]
figure.frameon: True
figure.max_open_warning: 20
figure.subplot.bottom: 0.1
figure.subplot.hspace: 0.2
figure.subplot.left: 0.125
figure.subplot.right: 0.9
figure.subplot.top: 0.9
figure.subplot.wspace: 0.2
font.cursive: ['Apple Chancery', 'Textile', 'Zapf Chancery', 'Sand', 'cursive']
font.family: ['serif']
font.fantasy: ['Comic Sans MS', 'Chicago', 'Charcoal', 'ImpactWestern', 'fantasy']
font.monospace: ['Bitstream Vera Sans Mono', 'DejaVu Sans Mono', 'Andale Mono', 'Nimbus Mono L', 'Courier New', 'Courier', 'Fixed', 'Terminal', 'monospace']
font.sans-serif: ['Bitstream Vera Sans', 'DejaVu Sans', 'Lucida Grande', 'Verdana', 'Geneva', 'Lucid', 'Arial', 'Helvetica', 'Avant Garde', 'sans-serif']
font.serif: ['Bitstream Vera Serif', 'DejaVu Serif', 'New Century Schoolbook', 'Century Schoolbook L', 'Utopia', 'ITC Bookman', 'Bookman', 'Nimbus Roman No9 L', 'Times New Roman', 'Times', 'Palatino', 'Charter', 'serif']
font.size: 12
font.stretch: normal
font.style: normal
font.variant: normal
font.weight: normal
grid.alpha: 1.0
grid.color: k
grid.linestyle: :
grid.linewidth: 0.5
image.aspect: equal
image.cmap: jet
image.interpolation: bilinear
image.lut: 256
image.origin: upper
image.resample: False
interactive: False
keymap.all_axes: a
keymap.back: ['left', 'c', 'backspace']
keymap.forward: ['right', 'v']
keymap.fullscreen: ('f', 'ctrl+f')
keymap.grid: g
keymap.home: ['h', 'r', 'home']
keymap.pan: p
keymap.quit: ('ctrl+w', 'cmd+w')
keymap.save: ('s', 'ctrl+s')
keymap.xscale: ['k', 'L']
keymap.yscale: l
keymap.zoom: o
legend.borderaxespad: 0.5
legend.borderpad: 0.4
legend.columnspacing: 2.0
legend.fancybox: False
legend.fontsize: large
legend.frameon: True
legend.handleheight: 0.7
legend.handlelength: 2.0
legend.handletextpad: 0.8
legend.isaxes: True
legend.labelspacing: 0.5
legend.loc: upper right
legend.markerscale: 1.0
legend.numpoints: 2
legend.scatterpoints: 3
legend.shadow: False
lines.antialiased: True
lines.color: b
lines.dash_capstyle: butt
lines.dash_joinstyle: round
lines.linestyle: -
lines.linewidth: 1.0
lines.marker: None
lines.markeredgewidth: 0.5
lines.markersize: 6
lines.solid_capstyle: projecting
lines.solid_joinstyle: round
mathtext.bf: serif:bold
mathtext.cal: cursive
mathtext.default: it
mathtext.fallback_to_cm: True
mathtext.fontset: cm
mathtext.it: serif:italic
mathtext.rm: serif
mathtext.sf: sans\-serif
mathtext.tt: monospace
patch.antialiased: True
patch.edgecolor: k
patch.facecolor: b
patch.linewidth: 1.0
path.effects: []
path.simplify: True
path.simplify_threshold: 0.111111111111
path.sketch: None
path.snap: True
pdf.compression: 6
pdf.fonttype: 3
pdf.inheritcolor: False
pdf.use14corefonts: False
pgf.debug: False
pgf.preamble: ['']
pgf.rcfonts: True
pgf.texsystem: xelatex
plugins.directory: .matplotlib_plugins
polaraxes.grid: True
ps.distiller.res: 6000
ps.fonttype: 3
ps.papersize: letter
ps.useafm: False
ps.usedistiller: False
savefig.bbox: None
savefig.directory: ~
savefig.dpi: 100
savefig.edgecolor: w
savefig.extension: png
savefig.facecolor: w
savefig.format: png
savefig.frameon: True
savefig.jpeg_quality: 95
savefig.orientation: portrait
savefig.pad_inches: 0.1
svg.embed_char_paths: True
svg.fonttype: path
svg.image_inline: True
svg.image_noscale: False
text.antialiased: True
text.color: k
text.dvipnghack: None
text.hinting: True
text.hinting_factor: 8
text.latex.preamble: ['']
text.latex.preview: False
text.latex.unicode: False
text.usetex: True
timezone: UTC
tk.pythoninspect: False
tk.window_focus: False
toolbar: toolbar2
verbose.fileo: sys.stdout
verbose.level: silent
webagg.open_in_browser: True
webagg.port: 8988
webagg.port_retries: 50
xtick.color: k
xtick.direction: in
xtick.labelsize: medium
xtick.major.pad: 4
xtick.major.size: 4
xtick.major.width: 0.5
xtick.minor.pad: 4
xtick.minor.size: 2
xtick.minor.width: 0.5
ytick.color: k
ytick.direction: in
ytick.labelsize: medium
ytick.major.pad: 4
ytick.major.size: 4
ytick.major.width: 0.5
ytick.minor.pad: 4
ytick.minor.size: 2
ytick.minor.width: 0.5
Publicado 07/10/2014 em 18:17
fonte usuário
Em outras línguas...                            


1 respostas

votos
0

Eu consertei isso! Acontece que o culpado estava usando a versão do Miktex 64 bits ...

Respondeu 09/10/2014 em 19:55
fonte usuário

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more