Matplotlib - 为什么只有最后一个条调整每个部分的宽度?
Matplotlib - why is only the last bar adjusting width in each part?
我无法理解为什么当我将宽度从 0.2 更改为 0.5 时,只有最右边的系列 (group_c) 会发生变化。有人 运行 参与其中吗?
包含图片以供图形输出参考。
- a - o 只是 rand 整数
group_a = (a,b,c,d,e)
group_b = (f,g,h,i,j)
group_c = (k,l,m,n,o)
width = 0.5
x = np.arange(5)
#I think it is something in here, but not sure what
plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x, group_b, width, color = 'orange')
plt.bar(x+0.2, group_c, width, color = 'green')
plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")
plt.ylabel('%')
plt.legend(['Group A','Group B','Group C'])
plt.show()
[输出图片]
我猜宽度是正确的,但条形只是一个接一个。也许,通过使用 alpha 添加一些透明度,您可以清楚地看到它。
group_a = (a,b,c,d,e)
group_b = (f,g,h,i,j)
group_c = (k,l,m,n,o)
width = 0.5
x = np.arange(5)
plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x, group_b, width, alpha = .5, color = 'orange')
plt.bar(x+0.2, group_c, width, alpha = .1, color = 'green')
plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")
plt.ylabel('%')
plt.legend(['Group A','Group B','Group C'])
plt.show()
这些条只是重叠,因为偏移量小于条的宽度。通过更改将它们添加到图中的顺序,您可以看到不同的重叠。
import matplotlib.pyplot as plt
import numpy as np
group_a = 5*[20]
group_b = 5*[40]
group_c = 5*[100]
width = 0.5
x = np.arange(5)
#I think it is something in here, but not sure what
plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x+0.2, group_c, width, color = 'green')
plt.bar(x, group_b, width, color = 'orange')
plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")
plt.ylabel('%')
plt.legend(['Group A','Group B','Group C'])
plt.show()
我无法理解为什么当我将宽度从 0.2 更改为 0.5 时,只有最右边的系列 (group_c) 会发生变化。有人 运行 参与其中吗?
包含图片以供图形输出参考。
- a - o 只是 rand 整数
group_a = (a,b,c,d,e)
group_b = (f,g,h,i,j)
group_c = (k,l,m,n,o)
width = 0.5
x = np.arange(5)
#I think it is something in here, but not sure what
plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x, group_b, width, color = 'orange')
plt.bar(x+0.2, group_c, width, color = 'green')
plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")
plt.ylabel('%')
plt.legend(['Group A','Group B','Group C'])
plt.show()
[输出图片]
我猜宽度是正确的,但条形只是一个接一个。也许,通过使用 alpha 添加一些透明度,您可以清楚地看到它。
group_a = (a,b,c,d,e)
group_b = (f,g,h,i,j)
group_c = (k,l,m,n,o)
width = 0.5
x = np.arange(5)
plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x, group_b, width, alpha = .5, color = 'orange')
plt.bar(x+0.2, group_c, width, alpha = .1, color = 'green')
plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")
plt.ylabel('%')
plt.legend(['Group A','Group B','Group C'])
plt.show()
这些条只是重叠,因为偏移量小于条的宽度。通过更改将它们添加到图中的顺序,您可以看到不同的重叠。
import matplotlib.pyplot as plt
import numpy as np
group_a = 5*[20]
group_b = 5*[40]
group_c = 5*[100]
width = 0.5
x = np.arange(5)
#I think it is something in here, but not sure what
plt.bar(x-0.2, group_a, width, color = 'cyan')
plt.bar(x+0.2, group_c, width, color = 'green')
plt.bar(x, group_b, width, color = 'orange')
plt.xticks(x, ['1','2','3','4','5'])
plt.xlabel("quarter")
plt.ylabel('%')
plt.legend(['Group A','Group B','Group C'])
plt.show()