I have data in pandas DataFrame
:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
np.random.seed(786)
df = pd.DataFrame({'a':np.arange(0, 1, 0.05),
'b':np.random.rand(20) - .5})
print (df)
a b
0 0.00 0.256682
1 0.05 -0.192555
2 0.10 0.393919
3 0.15 -0.113310
4 0.20 0.373855
5 0.25 -0.423764
6 0.30 -0.123428
7 0.35 -0.173446
8 0.40 0.440818
9 0.45 -0.016878
10 0.50 0.055467
11 0.55 -0.165294
12 0.60 -0.216684
13 0.65 0.011099
14 0.70 0.059425
15 0.75 0.145865
16 0.80 -0.019171
17 0.85 0.116984
18 0.90 -0.051583
19 0.95 -0.096527
I would like plot barplot
and add vertical line:
plt.figure(figsize=(10,5))
sns.barplot(x = 'a', y = 'b', data = df)
plt.vlines(x = 0.45, ymin = 0, ymax = 0.6, color = 'red', linewidth=5)
There are problems with ticklabels, because overlaping and also line should be in point 0.45
instaed near 0
for x axis
.
I try many solutions from link1, link2, link3, link4 but still problem set correctly axis for both plots.
What is problem? Is possible share x axis between plots?
Expected output - correctly aligned vertical line and also not overlaping ticks in x axis: