I am trying to plot multiple number of histograms by using .add_subplot()
Below is a part of my code:
for j in range(nlayer):
p_value_tensor_Wiki103_at_layer_j = p_value_tensor_Wiki103_at_layer[:,j].tolist()
hist_j = fig.add_subplot(grid[0,j], xticklabels=[], yticklabels=[])
hist_j.set_xlabel(labels_Wiki103[j],fontsize=3)
# histogram on the attached axes
hist_j.hist(p_value_tensor_Wiki103_at_layer_j, bins = 20)
But if I want to add a vertical lines at x= 0.05 on EACH of the subplot that I generated, what should I do?
Thank you,
Use matplotlib.pyplot.vlines or matplotlib.pyplot.axvline, usage:
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(1)
mu, sigma = 0.5, 0.15
x = mu + sigma * np.random.randn(10000)
fig, ax = plt.subplots(1)
ax.hist(x, 50, density=1)
ax.vlines(0.5,0,3)
plt.show()

ax.hist(x, 50, density=1)
ax.axvline(0.5)
plt.show()

In your use case you would simply need to do
for j in range(nlayer):
#...
hist_j.axvline(0.5)
# or to draw a line from ymin to ymax
hist_j.vlines(0.5, ymin, ymax)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With