我想删除剧情边界内的额外空间
plt.boxplot(parkingData_agg['occupancy'], 0, 'rs', 0, 0.75)
plt.tight_layout() # This didn't work. Maybe it's not for the purpose I am thinking it is used for.
plt.yticks([0],['Average Occupancy per slot'])
fig = plt.figure(figsize=(5, 1), dpi=5) #Tried to change the figsize but it didn't work
plt.show()
答案 0 :(得分:5)
代码中命令的顺序有点混乱。
tight_layout
,以便可以考虑长标签。 pos=[0]
)这些变化将导致以下情节
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rayleigh(scale=7, size=100)
fig = plt.figure(figsize=(5, 2), dpi=100)
plt.boxplot(data, False, sym='rs', vert=False, whis=0.75, positions=[0])
plt.yticks([0],['Average Occupancy per slot'])
plt.tight_layout()
plt.show()
然后,您可以更改箱线图的widths
以匹配所需的结果,例如
plt.boxplot(..., widths=[0.75])
你当然可以将你的情节放在一个子图中,而不是让轴填满图的整个空间,例如。
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rayleigh(scale=7, size=100)
fig = plt.figure(figsize=(5, 3), dpi=100)
ax = plt.subplot(3,1,2)
ax.boxplot(data, False, sym='rs', vert=False, whis=0.75, positions=[0], widths=[0.5])
plt.yticks([0],['Average Occupancy per slot'])
plt.tight_layout()
plt.show()
答案 1 :(得分:0)
使用subplots_adjust
fig = plt.figure(figsize=(5, 2))
axes = fig.add_subplot(1,1,1)
axes.boxplot(parkingData_agg['occupancy'], 0, 'rs', 0, 0.75)
plt.subplots_adjust(left=0.1, right=0.9, top=0.6, bottom=0.4)
#plt.boxplot(parkingData_agg['occupancy'], 0, 'rs', 0, 0.75)
#plt.tight_layout()
plt.yticks([0],['Average Occupancy per slot'])
plt.show()