我正在使用x和y错误绘制一系列数据点,但不希望错误栏包含在图例中(仅限标记).有办法吗?

例:
import matplotlib.pyplot as plt
import numpy as np
subs=['one','two','three']
x=[1,2,3]
y=[1,2,3]
yerr=[2,3,1]
xerr=[0.5,1,1]
fig,(ax1)=plt.subplots(1,1)
for i in np.arange(len(x)):
ax1.errorbar(x[i],y[i],yerr=yerr[i],xerr=xerr[i],label=subs[i],ecolor='black',marker='o',ls='')
ax1.legend(loc='upper left', numpoints=1)
fig.savefig('test.pdf', bbox_inches=0)
Run Code Online (Sandbox Code Playgroud) 有很多关于处理lognormScipy发行的帖子,但我仍然不了解它.
2参数对数正态通常是由参数来描述\mu和\sigma其对应于Scipys loc=0和\sigma=shape,\mu=np.log(scale).
在scipy,lognormal分布 - 参数,我们可以阅读如何lognorm(\mu,\sigma)使用随机分布的指数生成样本.现在让我们尝试别的东西:
直接创建lognorm的问题是什么:
# lognorm(mu=10,sigma=3)
# so shape=3, loc=0, scale=np.exp(10) ?
x=np.linspace(0.01,20,200)
sample_dist = sp.stats.lognorm.pdf(x, 3, loc=0, scale=np.exp(10))
shape, loc, scale = sp.stats.lognorm.fit(sample_dist, floc=0)
print shape, loc, scale
print np.log(scale), shape # mu and sigma
# last line: -7.63285693379 0.140259699945 # not 10 and 3
Run Code Online (Sandbox Code Playgroud)
我使用拟合的返回值来创建拟合分布.但是我再次表现得很糟糕:
samp=sp.stats.lognorm(0.5,loc=0,scale=1).rvs(size=2000) # sample
param=sp.stats.lognorm.fit(samp) # fit the sample data
print param # does …Run Code Online (Sandbox Code Playgroud) 让我们说我正在用matplotlib绘制一条线并添加一个图例.在传说中它说------ Label.在绘制小图形尺寸进行打印时,我发现此线的默认水平长度有点太长.
是否有设置一个属性------ Label来--- Label?
我matplotlib用这个pyplot.hist()函数创建了一个直方图.我想sqrt(binheight)在条形图中添加bin height()的Poison错误平方根.我怎样才能做到这一点?
.hist()包含的返回元组return[2]- > 1个Patch对象的列表.我只能发现可以通过创建的条形图添加错误pyplot.bar().
我正在尝试使用matplotlib绘制直方图.我需要转换我的单行2D数组
[[1,2,3,4]] # shape is (1,4)
Run Code Online (Sandbox Code Playgroud)
进入1D阵列
[1,2,3,4] # shape is (4,)
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
使用drop_duplicates()方法时,我减少重复项,但也将所有NaNs项合并到一个条目中.如何在保留具有空条目的行(如np.nan, None or '')时删除重复项?
import pandas as pd
df = pd.DataFrame({'col':['one','two',np.nan,np.nan,np.nan,'two','two']})
Out[]:
col
0 one
1 two
2 NaN
3 NaN
4 NaN
5 two
6 two
df.drop_duplicates(['col'])
Out[]:
col
0 one
1 two
2 NaN
Run Code Online (Sandbox Code Playgroud) 我根据变量值中设置的值绘制补丁。
pc = PatchCollection(patches, match_original=True)
norm = Normalize()
cmap = plt.get_cmap('Blues')
pc.set_facecolor(cmap(norm(values)))
ax.add_collection(pc)
Run Code Online (Sandbox Code Playgroud)

现在我还想要一个额外的颜色条。如果我插入(例如在 set_facecolor 之前)
pc.set_array(values) # values
plt.colorbar(pc)
Run Code Online (Sandbox Code Playgroud)

它有效,但现在所有颜色都变成了灰度。以下内容set_facecolor不会改变任何内容。即使我cmap=在其中添加命令,plt.colorbar()所有内容仍保持灰度。我不知道该怎么办。