我正在尝试制作一个包括许多子情节的情节,我希望他们分享他们的轴心。我一直在尝试使用matplotlib.ticker.MaxNLocator
来修剪我的记号上的标签,这样图形就有了可读的轴。但是,不管我是使用prune='upper'
、'lower'
、还是{
下面是我使用的代码的一个稍微简化的版本(尽管仍然相当长,抱歉):
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as tck
chains = np.array([[-.4, 4, 0, 0, 0], [6, 19, 2000, 2.1e16, 6.1e13]])
pars = np.array([r'$SF_\infty$', r'$\tau_D$', r'$\tau$', 'width', 'scale'])
nplots = len(chains[0,:]) - 1
# Fix up matplotlib to give plots like you like
mpl.rcParams.update({'font.size': 6, 'font.family': 'serif', 'mathtext.fontset': 'cm', 'mathtext.rm': 'serif',
'lines.linewidth': .7, 'xtick.top': True, 'ytick.right': True})
# Make a plot
fig = plt.figure()
for i in range(1,nplots+1):
for j in range(nplots):
if (j<i):
ax = plt.subplot(nplots, nplots, (i-1)*nplots+j+1)
plt.plot(chains[ :, j ], chains[ :, i ], '.-', markersize=0.3, alpha=0.5)
# Set aspect
xlim, ylim = ax.get_xlim(), ax.get_ylim()
ax.axis([xlim[0], xlim[1], ylim[0], ylim[1]])
ax.set_aspect( float(xlim[1]-xlim[0]) / (ylim[1]-ylim[0]) )
# Print things around the edges
if (j == 0): plt.ylabel(pars[i])
if (i == nplots): plt.xlabel(pars[j])
if (j != 0): ax.tick_params(labelleft=False)
if (i != nplots): ax.tick_params(labelbottom=False)
if (j != i-1):
ax.get_xaxis().get_offset_text().set_visible(False)
ax.get_yaxis().get_offset_text().set_visible(False)
# End if-statements
# Fix tickers
ax.minorticks_on()
ax.tick_params(which='both', direction='inout', width=0.5)
ax.xaxis.set_major_locator(tck.MaxNLocator(nbins=5, prune='both'))
ax.yaxis.set_major_locator(tck.MaxNLocator(nbins=5, prune='both'))
# Saving file
plt.subplots_adjust(hspace=0, wspace=-.58)
plt.savefig('testing.png', dpi=400, bbox_inches='tight')
plt.close('all')
我在cdam函数中的用法是什么?我使用的是Matplotlib 2.0.0。在
(很明显,对于如何提高此图的可读性和减少硬编码量的任何评论都是非常感谢的!)在
目前没有回答
相关问题 更多 >
编程相关推荐