Nice programing

Mac OSX에 Matplotlib 플롯이 표시되지 않습니까?

nicepro 2020. 11. 9. 21:00
반응형

Mac OSX에 Matplotlib 플롯이 표시되지 않습니까?


Mac OSX 10.5.8을 실행하고 있습니다. macports를 사용하여 matplotlib를 설치했습니다. 수정하지 않고 다음과 같은 matplotlib 갤러리에서 몇 가지 예제를 얻습니다.

http://matplotlib.sourceforge.net/examples/api/unicode_minus.html

나는 그것을 실행하고 오류가 없지만 그림이 나타나지 않습니다. Linux Ubuntu에서 나는 그것을 얻습니다.

여기서 무엇이 잘못 될 수 있는지 알고 있습니까?

감사


내 쪽에서도 확인할 수 있습니다. 수정하기 위해 내가 한 작업은 다음과 같습니다.

sudo port install py25-matplotlib +cairo+gtk2
sudo port install py26-matplotlib +cairo+gtk2

또한 기본 백엔드를 GUI 기반 백엔드로 변경해야합니다.

파일을 편집 ~/.matplotlib/matplotlibrc하고 다음을 추가합니다.

backend: GTKCairo

또한 GTK 또는 Cairo 백엔드가 필요하지 않을 수있는 다음을 시도 할 수 있습니다. 편집 ~/.matplotlib/matplotlibrc및 추가 :

backend: MacOSX

이러한 변형이 설치된 포트를 사용하면 작동하지만 X11이 필요하지 않습니다.


그건 그렇고, 내가 본 오류는 다음과 같습니다.

/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/__init__.py:41: UserWarning: 
Your currently selected backend, 'Agg' does not support show().
Please select a GUI backend in your matplotlibrc file ('/Users/wlynch/.matplotlib/matplotlibrc') or with matplotlib.use()
(backend, matplotlib.matplotlib_fname()))

새 응용 프로그램 창이 어떻게 만들어지고 즉시 사라 졌는지 확인할 수 있었지만 동일한 문제가 발생했습니다.

간단한 솔루션-가지고 있는지 확인하십시오.

plt.show()

음모 이후


이것이 나를 위해 일한 것입니다. 방금 Matplotlib 가져 오기를 변경했습니다.

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

시도 할 때

plt.savefig('myfilename.png')

대신에

plt.show()

myfilename.png현재 경로에 이름이 지정된 올바른 이미지를 저장 합니까?


메모를 추가하기 위해

matplotlibrc 파일이 내 시스템에 없어서 matplotlib 웹 사이트에서 사본을 다운로드해야했습니다. 향후 사용자도 똑같이해야 할 수도 있습니다.


이것은 나를 위해 일한 것입니다.

brew install pkg-config
brew link pkg-config
brew install pygtk
brew install freetype
brew install libpng

sudo ln -s /usr/local/Cellar/freetype/*/lib/pkgconfig/freetype2.pc /usr/local/lib/pkgconfig/freetype2.pc

git clone git@github.com:matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install

참조 :

http://blog.caoyuan.me/2012/08/matplotlib-error-mac-os-x/ http://matplotlib.org/faq/installing_faq.html#install-from-git http : //www.tapir .caltech.edu / ~ dtsang / python.html


나는 파이썬 2.5 만 가지고 있었고 내 Mac에 파이썬 2.6을 설치하고 싶지 않았습니다. 그래서이 문제를 해결하기 위해 다음 링크에 언급 된 다른 절차를 사용했습니다.

http://www.gtkforums.com/viewtopic.php?f=3&t=54928

실제로 필요한 것은 다음 단계입니다.

1) "pygtk-2.0.pc"디렉토리를 검색하여 찾습니다. 예를 들어 광산은 다음 디렉토리에 있습니다.

/ opt / local / lib / pkgconfig

2) 환경 변수에 경로 정보 추가. 예를 들면 :

PKG_CONFIG_PATH=/opt/local/lib/pkgconfig
export PKG_CONFIG_PATH

3) matplotlib 웹 사이트 http://matplotlib.sourceforge.net/_static/matplotlibrc 에서 구성 정보 파일 "matplotlibrc"를 다운로드합니다 .

4) 파일에서 백엔드를 MacOSX로 변경하고 저장하십시오.

5) 파일을 .matplotlib 디렉토리에 복사합니다. 다음 명령을 사용하여 python에서 디렉토리를 찾을 수 있습니다.

import matplotlib
matplotlib.get_configdir()

Mac comes with its own python (read from here, which is not the best), I would suggest just a clean install of some Python 3.7 or so along with Anaconda and then introduce them as interpreters to PyCharm. anything will work fine and you wont need to add ad-hoc solutions like "backend: MacOSX" or so.


Do the following if anyone is using spyder.

1.) Start Spyder 2.3.5.2 from Anaconda Launcher 2.) Go to preferences -> IPython console -> Graphics -> Backend: changed it to "Automatic" 3.) Select "Apply" and close preferences 3.) Restart IPython kernel 4.) Create simple graphic like


As a temporary work around one can save the figure to a .png/.jpg/.pdf and make use of that file for the moment.

## assuming price is out DataFrame that contains columns that we want to plot 
pdf_plot=price.plot().get_figure()  
pdf_plot.savefig('Stocks.pdf')

sudo port install py37-matplotlib +cairo+gtk3
~/.matplotlib/matplotlibrc used 
backend: MacOSX

Seemed to work on MacOS Mojave 10.14.4 with python 3.7 on the unicode_minus.py example above.

참고URL : https://stackoverflow.com/questions/2512225/matplotlib-plots-not-showing-up-in-mac-osx

반응형