简体   繁体   English

我怎样才能在同一张图上 plot 4 个直方图

[英]how can I plot 4 histograms on the same graph


I have the following problem:我有以下问题:
I am using hist() in matplotlib.pyplot我在 matplotlib.pyplot 中使用 hist()
I am trying to create 4 histograms on the same graph.我正在尝试在同一张图上创建 4 个直方图。 and an approximation gaussian for each one of them.以及它们中的每一个的近似高斯。
how can I plot the 4 histograms on the same graph, without them blocking each other (side by side)?我怎样才能 plot 在同一张图上的 4 个直方图,而不会相互阻挡(并排)? any ideas?有任何想法吗?

There are several examples in the matplotlib documentation . matplotlib 文档中有几个示例。 This one looks like it answers your question:这个看起来像是回答了你的问题:

import numpy as np
import pylab as P
#
# first create a single histogram
#
mu, sigma = 200, 25
x = mu + sigma*P.randn(10000)
#
# finally: make a multiple-histogram of data-sets with different length
#
x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

# and exercise the weights option by arbitrarily giving the first half
# of each series only half the weight of the others:

w0 = np.ones_like(x0)
w0[:len(x0)/2] = 0.5
w1 = np.ones_like(x1)
w1[:len(x1)/2] = 0.5
w2 = np.ones_like(x2)
w0[:len(x2)/2] = 0.5



P.figure()

n, bins, patches = P.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')

P.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Seaborn 在同一图上绘制多个直方图 - How To Plot Multiple Histograms On Same Plot With Seaborn 如何在熊猫数据框的 1 个图形上绘制 2 个直方图 - How to plot 2 histograms on 1 graph from pandas dataframe 如何迭代多个 DataFrames 和 plot 直方图的每个特征,每个数据集的特征在同一个图中 - How to Iterate over multiple DataFrames and plot histograms for each feature with each data set's feature in the same graph 在同一图表上绘制来自DataFrame的两个直方图,指定轴 - Plot two histograms from DataFrame on the same graph, specifieng axises 在同一图表上绘制两个直方图,并使其列总和为100 - Plot two histograms on the same graph and have their columns sum to 100 如何在 python 的同一图中 plot 多条线? - How can I plot multiple line in the same graph in python? 我可以在3d中绘制几个直方图吗? - Can I plot several histograms in 3d? 大熊猫怎么能在同一个图中绘制2个pdf? - how can pandas plot 2 pdf in same graph? 如何在同一图中绘制三个直方图,其中每个直方图必须代表一个值范围? - how I plot three histograms in the same figure where each of them must represent a range of values? 如何使用 plot 信号 plot 在同一图中的子区间的信号统计(方差)? - How can I plot signal statistics(variance) of subintervals in the same graph with signal plot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM