绘制条形宽度恒定但条带大小不同的直方图

时间:2019-02-04 18:30:07

标签: python python-2.7 matplotlib histogram

我有一个Python脚本,该脚本可生成三个数据集的单个直方图,其中bin大小以列表形式提供。 Python脚本sippet如下:

<html>
  <body>
    <nav class="navbar">
      <div class="container">
        <div class="NavLeft">
          <img src="https://www.google.de/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" width=130 height=40>
          <a>Home</a>
          <a>First Link</a>
          <a>Second Link</a>
          <a>Home</a>
          <a>First Link</a>
          <a>Second Link</a>
        </div>
        <div class="NavRight">
          <a>Account</a>
        </div>
      </div>
    </nav>
  </body>
</html>

此处,稍后附加到body{ margin: 0; } img{ margin-right: 50px; } a{ padding: 10px; cursor: pointer; color: white; font-family: Helvetica } a:hover { text-decoration: underline } .navbar { background: #22292f; padding:0 100px ; } .container{ margin: auto; max-width:1200px; display: flex; justify-content: space-between; padding: 10px 0; } .NavLeft{ display: flex; flex-wrap: wrap; height: 40px; } .NavRight{ display: flex; } 的元素是给定数据的最大值。因此最后一个纸槽尺寸将与其他纸槽尺寸不同。
上面的脚本片段以及脚本的其余部分产生了以下图:
Histogram 除了一个问题,这很好。我需要所有的条都具有相同的大小,我不希望条的大小取决于垃圾箱的大小,这在我看来不是很好。
关于hist()的matplotlib文档说,参数“ rwidth”可用于调整条宽度,仍相对于箱尺寸,这是当前正在执行的操作,对我没有用。
因此,当使用非均匀的bin大小时,如何保持matplotlib直方图的条形宽度相同?

注意:它看起来像是this帖子的副本,但事实并非如此。我没有在X轴上使用对数刻度。

1 个答案:

答案 0 :(得分:0)

这有点不合常规。但是public class PdModel { [Key] public int Id { get; set; } public string ModelCode { get; set; } public string ModelName { get; set; } public string ModelComment { get; set; } public string ModelDescription { get; set; } public string ModelAnnotation { get; set; } public string ModelDatabase { get; set; } public DateTime? ModelCreationDate { get; set; } public string ModelCreationUser { get; set; } public DateTime? ModelModificationDate { get; set; } public string ModelModificationUser { get; set; } public string ModelGarantExtendedFlag { get; set; } public string ModelColumnExtendedFlag { get; set; } public string ModelTableExtendedFlag { get; set; } public DateTime PdInsertedDate { get; set; } public ICollection<PdRule> pdRules { get; set; } public ICollection<PdModelExtended> pdModelExtendeds {get;set;} public ICollection<PdTable> PdTables { get; set; } public ICollection<PdReference> PdReferences { get; set; } public ICollection<PdModelSource> PdModelSources { get; set; } public ICollection<PdDomain> pdDomains { get; set; } public ICollection<PdView> pdViews { get; set; } [ForeignKey("Id")] public virtual PdFolderTree pdFolderTree { get; set; } } public class PdReference { public int Id { get; set; } public int ModelId { get; set; } public string ModelCode { get; set; } public string ReferenceCode { get; set; } public string ReferenceName { get; set; } public string ReferenceComment { get; set; } public string ReferenceDescription { get; set; } public string ReferenceAnnotation { get; set; } public string ReferenceStereotype { get; set; } public int ParentModelId { get; set; } public string ParentModelCode { get; set; } public string ParentTableCode { get; set; } public int ParentTableId { get; set; } public int ChildTableId { get; set; } public string ChildTableCode { get; set; } public string Cardinality { get; set; } public DateTime PdInsertedDate { get; set; } [ForeignKey("ModelId")] public PdModel PdModels { get; set; } public ICollection<PdJoin> pdJoins { get; set; } [ForeignKey("ChildTableId")] public virtual PdTable pdChildTable { get; set; } 返回每个bin中的元素数。您可以使用此数据(或从plt.hist跳过对原始直方图的绘制)来创建宽度相等的“条形图”。

numpy.histogram