Home > Software engineering >  Many plots on one graph (horizontal and vertical) in matplotlib
Many plots on one graph (horizontal and vertical) in matplotlib

Time:09-28

Hey this is the plot which I want to create enter image description here

And here are the details: on x axis I want to have the numbers from 0 to 10, on y axis I want to have values from 0 do 60. For each i from interval [0, 10], I have 10000 numbers. Black line is the mean of all the numbers for each i. For selected is (i=2 and i=6 on the graph) I want to plot histogram vertically. What is important I want to use density=True in hist function. The most difficult part is to fix the height of all the histograms to 3 in terms of x axis values (red one starts at 2 and the highest point is at 5 and the blue one starts at 6 and ends at 9 so the height is 3). Is anyone able to help me? Below is my current code and the plot which is produced - unfortunately the height is much too small.

import numpy as np
import matplotlib.pyplot as plt

x = range(11)
res = np.random.randint(0, 60, size = (11, 10000))

means = [res[i, :].mean() for i in x]

fig, ax = plt.subplots(figsize = (12, 6), dpi = 300)

ax.plot(x, means)
ax.hist(res[2,:], bins = 100, density = True, orientation = 'horizontal', bottom = 2)

enter image description here

CodePudding user response:

Here is a stab at it - Example histogram with new width

  • Related