2
我试图创建一个带seaborn的直方图,其中bin从0开始并转到1.但是,只有在0.22到0.34范围内的日期。为了更好地呈现数据,我希望空白空间更具视觉效果。扩展seaborn直方图中bin的范围
创建我的片材
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
%matplotlib inline
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('svg', 'pdf')
df = pd.read_excel('test.xlsx', sheetname='IvT')
在这里,我创建了一个变量为我的列表和一个我认为应该定义直方图的区间范围内。
st = pd.Series(df['Short total'])
a = np.arange(0, 1, 15, dtype=None)
和直方图本身看起来像这样
sns.set_style("white")
plt.figure(figsize=(12,10))
plt.xlabel('Ration short/total', fontsize=18)
plt.title ('CO3 In vitro transcription, Na+', fontsize=22)
ax = sns.distplot(st, bins=a, kde=False)
plt.savefig("hist.svg", format="svg")
plt.show()
它创建了一个图表位X从0到0.2050和y在-0.04至0.04的范围内。与我所期望的完全不同。我谷歌搜索相当一段时间,但似乎无法找到我的具体问题的答案。
已经,谢谢你的帮助。
非常感谢你。那就是诀窍。有没有办法,我也可以使用下面的参数来获得酒吧周围的边框? hist_kws = dict(edgecolor =“k”,linewidth = 2) – Jul
@Jul'hist_kws'将参数从matplotlib发送到底层直方图函数。您可以通过阅读文档来查看所有可以传递的参数:'import matplotlib.pyplot as plt; ?plt.hist'在这种情况下,您希望将'histtype'指定为''bar''。不要忘记接受和upvote这个答案它解决了你的问题。 –
如果我将直方图的代码更改为ax = sns.distplot(st,bins = 34,kde = False,color ='#007b7f',histtype ='bar',hist_kws = dict(edgecolor =“k”,linewidth = 2))它给了我一个错误消息,说:_distplot()有一个意外的关键字参数'histtype'_。或者我必须更改matplotlib中的组织类型? – Jul