当我在另一列上绘制2列时,会绘制不同的图 [英] When I plot 2 columns one over the other, a different graph is plotted
问题描述
我从2个相同大小的np.arrays中有2列.当我绘制唯一的一个时,我得到以下结果:
I have 2 columns from 2 np.arrays of the same size. When I plot the only the one I get this result:
plt.figure(figsize=(70,10))
for i,h in enumerate(clean_head):
plt.subplot(1,6,i+1)
#plt.hist(non_fire[:,i],alpha=.3)
plt.hist(fire[:,i],alpha=.3)
plt.title(clean_head[i])
# plt.tight_layout()
当我同时绘制它们时,我得到了:
When I plot both I get this:
plt.figure(figsize=(70,10))
for i,h in enumerate(clean_head):
plt.subplot(1,6,i+1)
plt.hist(non_fire[:,i],alpha=.3)
plt.hist(fire[:,i],alpha=.3)
plt.title(clean_head[i])
# plt.tight_layout()
两个直方图中的任何一个都不与首字母相同.我不知道哪个是粉红色的,哪个是浅蓝色的图形.
Where no one of the two histograms is the same with the initial. I dont understand which is the pink and which is the lightblue graph.
我还有16个这样的地块,而我所有地块都有相同的问题.
I have 16 more plots like that and I have the same problem with all of them.
推荐答案
在第二组图中,蓝色直方图用于非开火"情况,橙色直方图用于开火"情况.如果要绘制第三个直方图,它将为绿色.通常,您可以使用参数颜色.
in the second set of plots the blue histogram is for the "non-fire"-case and the orange one is for the "fire"-case. If you would plot a third histogram, it would be green. In general you can change the color of a given histogram using the parameter color.
直方图发生变化的原因是数组具有不同的值范围.您可以通过明确为bin提供功能来解决此问题:
The reason why your histograms change is that your arrays have different value ranges. You can fix this by explicitly giving bins the the function:
import matplotlib.pyplot as plt
import numpy as np
a = np.random.rand(100)
b = np.random.rand(100)*2
bins = np.linspace(min(np.min(a), np.min(b)), max(np.max(a), np.max(b)), 10)
plt.figure(figsize=(7,5))
plt.hist(a,alpha=.3, bins=bins)
#plt.hist(b,alpha=.3, bins=bins) #toggle this to see the effect
还请注意,直方图函数会返回其使用的bin列表.
Also note that histogram function returns the list of bins that it uses.
希望有帮助.
这篇关于当我在另一列上绘制2列时,会绘制不同的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!