我想为来自三个NOX源的N的同位素测量创建概率密度函数。测量量之间的数量在来源之间有所不同,因此我创建了三个数据范围。这是代码:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#import matplotlib.ticker as plticker
#from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
df = pd.DataFrame({
'Mobile':[15.6, 14.2, 14.4, 10.2, 13.1, 12.8, 13.3, 16.9, 15.8, 15.3, 16.9, 15.6, 15.6, 17, 16, 15.1, 15, 14.4,
14.6, 16.2, 15.3, 16.4, -0.4, -2.9, 1.6, 9.8, 1.6, -8.1, -4.4, -0.4, 8.6]})
df1 = pd.DataFrame({
'Soil':[-47, -37, -29, -26, -25, -24, -31, -23, -22, -19, -49, -42, -44, -37, -29, -29, -32, -31, -29, -28,
-26.5, -30.8]})
df2 = pd.DataFrame({
'Biomass Burning':[-2.7, -5, -5.9, -7.2, 3.2, 2.6, 3.8, 8.1, 12, 0.9, 1.3, 1.6, -1.5, -1.3, -0.1, 0.5, 4.4, 2,
2.9, 1.7, 3.2, 1.6, -0.3, -0.9]})
fig = plt.figure()
ax = fig.add_subplot()
ax.hist([df, df1, df2], label = ("Mobile", "Soil", "Biomass Burning"), bins=25, stacked=True, range=[0,25])
问题是我收到一条错误消息,上面写着: valueerror:x必须具有2个或更少的维度
。我已经尝试了一种“胖”方法,但是收到一个错误消息,该错误消息说 attributeError:'dataFrame'对象没有属性'Flatten'
。我不确定接下来要做什么以使代码运行并可以使用一些帮助。我还认为 Hist
可能是使用错误的功能,因为我想要概率密度分布。我也尝试过:
sns.displot(data=[df,df1,df2], x=['Mobile','Soil','Biomass Burning'], hue='target', kind='kde',
fill=True, palette=sns.color_palette('bright')[:3], height=5, aspect=1.5)
但是,我再次遇到了数据范围的问题不同。谢谢!
I would like to create a probability density function for the isotopic measurements of N from three NOx sources. The number of measurements varies between sources, so I've created three dataframes. Here is the code:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
#import matplotlib.ticker as plticker
#from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
df = pd.DataFrame({
'Mobile':[15.6, 14.2, 14.4, 10.2, 13.1, 12.8, 13.3, 16.9, 15.8, 15.3, 16.9, 15.6, 15.6, 17, 16, 15.1, 15, 14.4,
14.6, 16.2, 15.3, 16.4, -0.4, -2.9, 1.6, 9.8, 1.6, -8.1, -4.4, -0.4, 8.6]})
df1 = pd.DataFrame({
'Soil':[-47, -37, -29, -26, -25, -24, -31, -23, -22, -19, -49, -42, -44, -37, -29, -29, -32, -31, -29, -28,
-26.5, -30.8]})
df2 = pd.DataFrame({
'Biomass Burning':[-2.7, -5, -5.9, -7.2, 3.2, 2.6, 3.8, 8.1, 12, 0.9, 1.3, 1.6, -1.5, -1.3, -0.1, 0.5, 4.4, 2,
2.9, 1.7, 3.2, 1.6, -0.3, -0.9]})
fig = plt.figure()
ax = fig.add_subplot()
ax.hist([df, df1, df2], label = ("Mobile", "Soil", "Biomass Burning"), bins=25, stacked=True, range=[0,25])
The problem is that I get an error message that says: ValueError: x must have 2 or fewer dimensions
. I've tried a "fatten" method but get an error message that says AttributeError: 'DataFrame' object has no attribute 'flatten'
. I am unsure of what to try next to get the code to run and could use some help. I am also thinking that hist
might be the wrong function to use since I want a probability density distribution. I've also tried:
sns.displot(data=[df,df1,df2], x=['Mobile','Soil','Biomass Burning'], hue='target', kind='kde',
fill=True, palette=sns.color_palette('bright')[:3], height=5, aspect=1.5)
But again, I run into the issue of the dataframes being different lengths. Thanks!
发布评论
评论(1)
一个选项是
熔融
dataframes,concat
它们,然后使用hue
与strendot
:outption:output:
使用
var_name
和value_name
熔融>熔融
对于比“变量”和“ value”的有意义的标识符,例如,
One option is to
melt
the dataframes,concat
them, and then usehue
withdisplot
:Output:
Use the
var_name
andvalue_name
parameters ofmelt
for more meaningful identifiers than "variable" and "value", e.g.Output: