'Issue with y-ticks alignment in pandas bar chart
here is the data and code that I'm using to plot the bar chart as shown in the output plot. The issue is with y-ticks, I need to have y-ticks aligned in a vertical manner such that they cover/coincides with all four bars. If we use rot = 'some int value' the ticks rotate, but they do not exactly align vertically covering four bars.
| Polymer | Depth | Residual time |
|---|---|---|
| HPAM7030 | 50 | 1159 |
| HPAM7030 | 100 | 1638 |
| HPAM7030 | 200 | 2170 |
| HPAM7030 | 500 | 2718 |
| APAM7525 | 50 | 2040 |
| APAM7525 | 100 | 3101 |
| APAM7525 | 200 | 4176 |
| APAM7525 | 500 | 5270 |
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use(['science', 'notebook', 'grid'])
df.pivot(index = 'Polymer', columns = 'Depth', values = 'Residual time').plot(kind='barh')
plt.title('Residual time of different polymers (2 year simulation)')
plt.ylabel("Type of Polymer")
plt.xlabel("Residual time (Days)")
plt.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

