[Python] ImportError - matplotlib [fechada]

Discussão em 'Python' iniciado por Stack, Setembro 9, 2024.

  1. Stack

    Stack Membro Participativo

    Estou tentando plotar um histograma direto da biblioteca pandas usando o método .hist(), porém, me retorna um ImportError mesmo eu tendo instalado a biblioteca matplotlib após o primeiro erro.

    Segue o erro:

    {
    "name": "ImportError",
    "message": "matplotlib is required for plotting when the default backend \"matplotlib\" is selected.",
    "stack": "---------------------------------------------------------------------------
    ImportError Traceback (most recent call last)
    Cell In[21], line 1
    ----> 1 df_medidas.idade.hist()

    File ~/.local/share/virtualenvs/statistics-AJbd-G4v/lib/python3.11/site-packages/pandas/plotting/_core.py:128, in hist_series(self, by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, backend, legend, **kwargs)
    47 def hist_series(
    48 self: Series,
    49 by=None,
    (...)
    60 **kwargs,
    61 ):
    62 \"\"\"
    63 Draw histogram of the input series using matplotlib.
    64
    (...)
    126 >>> hist = ser.groupby(level=0).hist()
    127 \"\"\"
    --> 128 plot_backend = _get_plot_backend(backend)
    129 return plot_backend.hist_series(
    130 self,
    131 by=by,
    (...)
    141 **kwargs,
    142 )

    File ~/.local/share/virtualenvs/statistics-AJbd-G4v/lib/python3.11/site-packages/pandas/plotting/_core.py:1944, in _get_plot_backend(backend)
    1941 if backend_str in _backends:
    1942 return _backends[backend_str]
    -> 1944 module = _load_backend(backend_str)
    1945 _backends[backend_str] = module
    1946 return module

    File ~/.local/share/virtualenvs/statistics-AJbd-G4v/lib/python3.11/site-packages/pandas/plotting/_core.py:1874, in _load_backend(backend)
    1872 module = importlib.import_module(\"pandas.plotting._matplotlib\")
    1873 except ImportError:
    -> 1874 raise ImportError(
    1875 \"matplotlib is required for plotting when the \"
    1876 'default backend \"matplotlib\" is selected.'
    1877 ) from None
    1878 return module
    1880 found_backend = False

    ImportError: matplotlib is required for plotting when the default backend \"matplotlib\" is selected."
    }

    Continue reading...

Compartilhe esta Página