为什么Python图在不同的远程计算机上看起来如此不同?

时间:2018-09-12 11:48:43

标签: python matplotlib plot

我有一个生成图的python脚本,并在远程计算机上运行它。情节中的面板和字体是完美比例的,看起来就像我想要的那样。

我最近在不同远程计算机上运行了不变的代码,并且绘图显示出了不同的宽高比。

我已附上以下示例图。顶层外观如我所愿。下面的所有内容都是一样的,但是,不知何故,它实际上是风景而不是肖像。我曾尝试将figsize =(18.5 * 0.8,18.5)切换为figsize =(18.5,18.5 * 0.8),但这只会使情况变得更糟。

这些图是使用matplotlib.gridspec创建的。

有人可以解释为什么吗?我想这一定与不同远程机器的设置有关。

我有可能避免或撤消发生的更改吗?


MWE:

import argparse
import pylab as pb
pb.ion()
import numpy as np
import GPy
import math
import matplotlib
import matplotlib.pyplot as plt
import scipy as sc
from scipy import stats
import scipy.signal as ss
import sys
import Vfunctions as Vf
import os
from os.path import basename
import matplotlib as mpl
mpl.rcParams['axes.formatter.useoffset'] = False
mpl.rc('xtick', labelsize=20)
mpl.rc('ytick', labelsize=20)
import matplotlib.gridspec as gridspec

x_values = range(50)
y_values = np.sin(x_values)

print y_values

fig = plt.figure(figsize=(18.5*0.8, 18.5))

outer = gridspec.GridSpec(2, 1, height_ratios = [3,2])

gs1 = gridspec.GridSpecFromSubplotSpec(3, 1, subplot_spec = outer[0], hspace = .04)
ax1 = plt.subplot(gs1[0])
plt.plot(x_values,y_values,'k.')
ax1.set_xlim([0-1, 50])

xlabs = [0,100,200,300,400,500,600,700]
xlocs = [0/15.,100/15.,200/15.,300/15.,400/15.,500/15.,600/15.,700/15.]
ax1.set_xticks(xlocs)
ax1.set_xticklabels(xlabs)

plt.grid()

plt.tick_params(
    axis='x',          # changes apply to the x-axis                                                                                                                                                                                                                                                                   
    which='both',      # both major and minor ticks are affected                                                                                                                                                                                                                                                       
    bottom=False,      # ticks along the bottom edge are off                                                                                                                                                                                                                                                           
    top=False,         # ticks along the top edge are off                                                                                                                                                                                                                                                              
    labelbottom=False) # labels along the bottom edge are off                                                                                                                                                                                                                                                          

ax2 = plt.subplot(gs1[1])
ax2.errorbar(x_values, y_values, yerr=0.0001,fmt='k.')
plt.plot(x_values, y_values, 'k-')
plt.grid()


plt.tick_params(
    axis='x',          # changes apply to the x-axis                                                                                                                                                                                                                                                                   
    which='both',      # both major and minor ticks are affected                                                                                                                                                                                                                                                       
    bottom=False,      # ticks along the bottom edge are off                                                                                                                                                                                                                                                           
    top=False,         # ticks along the top edge are off                                                                                                                                                                                                                                                              
    labelbottom=False) # labels along the bottom edge are off                                                                                                                                                                                                                                                          


ax3 = plt.subplot(gs1[2])
plt.errorbar(x_values, y_values, yerr=0.0001,fmt='k.')
plt.grid()

gs2 = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec = outer[1], hspace = .5)
ax4 = plt.subplot(gs2[0])
plt.plot(x_values,y_values,'k.')
plt.grid()

fig.text(0.03,0.87,'Label 1',rotation='vertical', horizontalalignment='center', verticalalignment='center', size=26)
fig.text(0.03,0.7,'Label 2',rotation='vertical',horizontalalignment='center', verticalalignment='center',size=26)
fig.text(0.03,0.54,'Label 3',rotation='vertical',horizontalalignment='center', verticalalignment='center',size=26)
fig.text(0.03,0.24,'Label 4',rotation='vertical',horizontalalignment='center', verticalalignment='center',size=26)
fig.text(0.535,0.03,'Label 5',horizontalalignment='center', verticalalignment='center',size=26)
fig.text(0.535,0.415,'Label 6',horizontalalignment='center', verticalalignment='center',size=26)
fig.text(0.18,0.35,'Label 7',size=26)

plt.tight_layout(pad=6.0)

plt.savefig('plot.png')
plt.clf()

Code run on remote machine 1 Code run on remote machine 2


在具有良好图解的机器上进行画中画:

Brlapi==0.5.6
-e git+https://github.com/SheffieldML/GPy.git@775ce9e64c1e8f472083b8f2430134047d97b2fa#egg=GPy-dev
GnuPGInterface==0.3.2
Jinja2==2.6
Mako==0.5.0
MarkupSafe==0.15
MySQL-python==1.2.3
PAM==0.4.2
PIL==1.1.7
PRESTO==0.99
PyYAML==4.2b4
Pygments==1.4
Sphinx==1.1.3
Twisted-Core==11.1.0
Twisted-Names==11.1.0
Twisted-Web==11.1.0
adium-theme-ubuntu==0.3.2
apt-xapian-index==0.44
apturl==0.5.1ubuntu3
argparse==1.2.1
astropy==0.4.2
backports.ssl-match-hostname==3.4.0.2
certifi==14.05.14
chardet==2.0.1
command-not-found==0.2.44
configglue==1.0
configobj==4.7.2
cosmocalc==0.1.2
debtagshw==0.1
decorator==3.3.2
defer==1.0.2
dirspec==3.0.0
distribute==0.7.3
docutils==0.8.1
duplicity==0.6.18
emcee==3.0rc1
epydoc==3.0.1
h5py==2.6.0
httplib2==0.7.2
iotop==0.4.4
ipython==2.1.0
jockey==0.9.7
jsonschema==2.4.0
keyring==0.9.2
language-selector==0.1
launchpadlib==1.9.12
lazr.restfulclient==0.12.0
lazr.uri==1.0.3
lmfit==0.8.3
lockfile==0.8
logilab-astng==0.23.0
logilab-common==0.57.1
louis==2.3.0
lxml==2.3.2
matplotlib==1.4.2
mercurial==2.0.2
mock==1.0.1
nose==1.3.4
numexpr==1.4.2
numpy==1.9.1
nvidia-common==0.0.0
oauth==1.0.1
onboard==0.97.1
oneconf==0.2.8.1
pandas==0.16.2
pep8==0.6.1
pexpect==2.3
piston-mini-client==0.7.2
protobuf==2.4.1
psutil==2.1.3
pyOpenSSL==0.12
pybind11==2.2.3
pycrypto==2.4.1
pycups==1.9.61
pycurl==7.19.0
pyephem==3.7.5.1
pyfits==3.3
pyflakes==0.5.0
pygame==1.9.1release
pyinotify==0.9.2
pylint==0.25.0
pymc==2.3.4
pymix==0.8a
pyparsing==2.0.3
pyserial==2.5
pysmbc==1.0.13
pysqlite==1.0.1
python-apt==0.8.3ubuntu7.3
python-dateutil==1.5
python-debian==0.1.21ubuntu1
python-virtkey==0.60.0
pytz==2014.9
pyxdg==0.19
pyzmq==2.1.11
reportlab==2.5
rhythmbox-ubuntuone==4.2.0
rope==0.9.2
rpy==1.0.3
scikits.statsmodels==0.3.1
scipy==0.16.0
sessioninstaller==0.0.0
simplegeneric==0.7
simplejson==2.3.2
six==1.8.0
software-center-aptd-plugins==0.0.0
spyder==2.1.9
sympy==0.7.1.rc1
system-service==0.1.6
tables==2.3.1
tornado==4.1b2
traits==4.0.0
ubuntuone-couch==0.3.0
ubuntuone-installer==3.0.2
ubuntuone-storage-protocol==3.0.2
ufw==0.31.1-1
unattended-upgrades==0.1
unity-lens-video==0.3.5
unity-scope-video-remote==0.3.5
urlgrabber==3.9.1
usb-creator==0.2.23
virtualenv==15.0.2
wadllib==1.3.0
wsgiref==0.1.2
wxPython==2.8.12.1
wxPython-common==2.8.12.1
xdiagnose==2.5.3
xkit==0.0.0
xlrd==0.6.1
xlwt==0.7.2
yum-metadata-parser==1.1.2
zope.interface==3.6.1

在带有错误绘图的机器上进行画中画:

acor==1.1.1
alabaster==0.7.10
algopy==0.5.5
apipkg==1.4
appdirs==1.4.3
asn1crypto==0.24.0
asteval==0.9.12
astropy==2.0.1
astropy-helpers==2.0.6
Babel==2.5.1
backports-abc==0.5
backports.shutil-get-terminal-size==1.0.0
backports.ssl-match-hostname==3.5.0.1
bleach==2.0.0
certifi==2017.7.27.1
cffi==1.11.5
chardet==3.0.4
configparser==3.5.0
corner==2.0.1
coverage==4.5.1
coveralls==1.3.0
cryptography==2.2.2
cvxopt==1.1.9
cycler==0.10.0
Cython==0.26
decorator==4.1.2
docopt==0.6.2
docutils==0.14
emcee==2.2.1
enterprise==1.2.0
enterprise-extensions==0.0.0
entrypoints==0.2.3
enum34==1.1.6
ephem==3.7.6.0
execnet==1.4.1
funcsigs==1.0.2
functools32==3.2.3.post2
future==0.16.0
george==0.3.1
gnureadline==6.3.3
GPy==1.8.4
h5py==2.7.0
healpy==1.11.0
html5lib==0.999999999
idna==2.6
imagesize==0.7.1
ipaddress==1.0.19
ipykernel==4.6.1
ipython==5.4.1
ipython-genutils==0.2.0
ipywidgets==6.0.0
Jinja2==2.9.6
jplephem==2.7
jsonschema==2.6.0
jupyter==1.0.0
jupyter-client==5.1.0
jupyter-console==5.1.0
jupyter-core==4.3.0
libstempo==2.3.5
line-profiler==2.1.2
llvmlite==0.23.0
lmfit==0.9.11+4.g474ee30
magickwand==0.2
MarkupSafe==1.0
matplotlib==2.0.2
memory-profiler==0.52.0
mistune==0.7.4
mock==2.0.0
mpi4py==3.0.0
nanopipe==0.0
nbconvert==5.2.1
nbformat==4.3.0
nose==1.3.7
notebook==5.0.0
numba==0.38.0
numdifftools==0.9.20
numexpr==2.6.2
numpy==1.13.3
PAL2==2015.4
pandas==0.20.3
pandocfilters==1.4.2
paramz==0.8.5
pathlib2==2.3.0
patsy==0.4.1
pbr==3.1.1
pexpect==4.2.1
piccard==2016.1
pickleshare==0.7.4
Pillow==5.1.0
pint==0.5.3
pkginfo==1.4.1
PRESTO==0.99
prompt-toolkit==1.0.15
psutil==5.4.3
PTMCMCSampler==2015.2
ptyprocess==0.5.2
py==1.4.34
pybind11==2.2.3
pycparser==2.18
pyephem==3.7.6.0
pyfits==3.4
Pygments==2.2.0
pygsm==2.0.0
pymultinest==2.2
pyOpenSSL==17.5.0
pyparsing==2.2.0
pytest==3.2.1
pytest-forked==0.2
pytest-timeout==1.2.0
pytest-xdist==1.20.0
python-dateutil==2.6.1
pytz==2017.2
PyYAML==3.13
pyzmq==16.0.2
qtconsole==4.3.0
requests==2.18.4
requests-toolbelt==0.8.0
runipy==0.1.5
scandir==1.5
scikit-learn==0.19.1
scikit-sparse==0.4.3
scipy==1.0.0
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.11.0
snowballstemmer==1.2.1
sparklines==0.4.1
Sphinx==1.6.3
sphinx-rtd-theme==0.2.4
sphinxcontrib-websupport==1.0.1
statsmodels==0.8.0
subprocess32==3.2.7
terminado==0.6
testpath==0.3.1
torch==0.4.0
torchvision==0.2.1
tornado==4.5.1
tqdm==4.17.1
traitlets==4.3.2
twine==1.9.1
typing==3.6.2
uncertainties==3.0.2
urllib3==1.22
utils==0.9.0
Wand==0.4.4
wcwidth==0.1.7
webencodings==0.5.1
widgetsnbextension==2.0.0
wxPython==4.0.0rc1

0 个答案:

没有答案