简体   繁体   English

matplotlib图插入空白

[英]matplotlib figure inset whitespace

I'm making a figure for that includes an inset. 我为此制作了一个插图。 I cannot figure out how to get the whitespace on to be removed. 我无法弄清楚如何删除空白。 I've tried using tight_sublot() but it still leaves whitespace near the inset that I'd like to remove. 我试过使用tight_sublot()但是它仍然在要删除的插图附近留有空格。 Any suggestions? 有什么建议么?

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import silicon2_data

data = silicon2_data.out

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

for temperature in data:
    xs = temperature[:,0]
    ys = temperature[:,1]
    zs = temperature[:,2]
    ax.scatter(xs, ys, zs)
ax.set_zbound(0, 1.4)

ax.set_xlabel(r'$2\theta$ (degrees)')
ax.set_ylabel('Temperature (K)')
ax.set_zlabel(r'Intensity ($10^5$cts/sec)')
#inset
ax2 = fig.add_axes([0.15, 0.62, 0.25, 0.25])

ax2.plot(data[3,:,0], data[3,:,2],'bo')
ax2.plot(data[7,:,0], data[7,:,2],'rx')

ax2.legend(('16K', '18K'), loc=0, fontsize ='small')
ax2.set_ybound(0, 1.4)

plt.tight_layout()
plt.show()

This is roughly what I'm trying to make: 这大致就是我要做的:

在此处输入图片说明

After calling 打电话后

fig = plt.figure()

you can adjust characteristics of the subplots before adding them with fig.add_subplot() by using pyplot's subplots_adjust() method. 您可以使用pyplot的subplots_adjust subplots_adjust()方法,在使用fig.add_subplot fig.add_subplot()添加子图之前,调整子图的特征。 For your purposes, you might try 为了您的目的,您可以尝试

fig.subplots_adjust(wspace=0.05)
fig.subplots_adjust(hspace=0.05)

where the number is the fraction of the figure's width or height. 其中数字是图形的宽度或高度的分数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM