'Python - How to set exact values to the Y Axis
I already saw many explanations about the right way to do it. But, it seems I am not capable of seeing what I am doing wrong... I just want to have to the Y axe the values 0%, 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90% and 100%.
My code is:
MPPDataframe = pd.DataFrame(listaPDS, columns = ["Semanas"])
MPPDataframe["PlannedWorkPerWeek"] = PlannedWorkPerWeek
MPPDataframe["ActualWorkPerWeek"] = ActualWorkPerWeek
MPPDataframe["AcumPlannedWorkPerWeek"] = MPPDataframe["PlannedWorkPerWeek"].cumsum()
MPPDataframe["AcumActualWorkPerWeek"] = MPPDataframe["ActualWorkPerWeek"].cumsum(skipna=False)
MPPDataframe["PercentPlannedWorkPerWeek"] =
MPPDataframe["AcumPlannedWorkPerWeek"] / TotalPlannedWork
MPPDataframe["PercentPlannedWorkPerWeek"] =
MPPDataframe["PercentPlannedWorkPerWeek"].apply(lambda x: f'{x:.2%}')
MPPDataframe["PercentActualWorkPerWeek"] =
MPPDataframe["AcumActualWorkPerWeek"] / TotalPlannedWork
plt.figure(figsize=(12,8))
plt.grid(axis='y', linestyle='-')
plt.plot(MPPDataframe["Semanas"],MPPDataframe["PercentPlannedWorkPerWeek"],'g--',label="Planned Work per Week", marker='o',markersize=6)
plt.plot(MPPDataframe["Semanas"],MPPDataframe["PercentActualWorkPerWeek"],'b--',label="Actual Work per Week", marker='x',markersize=6)
plt.xlabel('Weeks', color="Blue")
plt.xticks(rotation=75)
plt.yticks(np.arange(0,100,10))
plt.legend()
plt.title('S Curve')
plt.show()
Solution 1:[1]
First of all, when yoh had some problems with matplotlib, check official documentation: https://matplotlib.org/3.5.1/api/_as_gen/matplotlib.pyplot.yticks.html
plt.yticks(np.arange(0,10,100))
that`s wrong, because np.arange have a three arguments: (end, stop, step), but your step is much bigger than interval between yours start and ending points) the right one is that (i used 101 because stop point is not included in np.arange function, and if we use 100 it will be stoped on 90 and not include 100) :
plt.yticks(np.arange(0, 101, 10))
or if you need text percent labels, create yticks like that:
plt.yticks(np.arange(0, 101, 10), ['0%', '10%', '20%', ... etc to '100%'])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
