请让我知道如何增加图表的大小并将条形隔开以进行更整洁的演示。我使用的代码已正式上传。
问问题
27 次
2 回答
0
您可以执行以下操作之一:
- 增加图像的大小:
fig, ax = plt.subplots(figsize=[10, 4]) # This sets the size of the output to be 10x4.
- 设置 xlabels
locations = np.arange(len(names))
labels = ['Ben', 'John', 'Jack'] #sample, note that length of labels SHOULD match len of locations.
plt.xticks(locations, labels, rotation=45) #rotation is optional
- 旋转 xticklabels
plt.xticks(rotations=90) # Rotating the ticks by 90 degree
于 2022-01-08T07:40:17.183 回答
0
您可以在plt.hist中使用rwidth。看到这个:
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
x = [21,22,23,4,5,6,77,8,9,10,31,32,33,34,35,36,37,18,49,50,100]
num_bins = 5
n, bins, patches = plt.hist(x, num_bins, facecolor='blue', alpha=0.5, rwidth=0.5)
plt.show()
输出:
如果你想使用 plt.bar,你可以使用这个示例:
import matplotlib.pyplot as plt
height =[21,22,23,4,5]
bars = ('A', 'B', 'C', 'D', 'E')
x_pos = [0, 1, 2, 3, 4]
plt.bar(x_pos, height,width=0.5)
plt.xticks(x_pos, bars)
plt.show()
输出 :
于 2022-01-08T07:38:23.973 回答