This is my code.
fig, ax1 = plt.subplots()
fig.set_figheight(7)
fig.set_figwidth(12)
ax1.bar(df.index, df['occurence of defects'], color="C0")
ax1.set_ylabel("Qty", color="C0")
ax1.tick_params(axis="y", colors="C0")
ax1.set_xlabel("Defect")
ax1.set_xticklabels(df['Name of Defect'],rotation=45)
ax2 = ax1.twinx()
ax2.plot(df.index, df["cum percentage"], color="C1", marker="D", ms=7)
ax2.yaxis.set_major_formatter(PercentFormatter())
ax2.tick_params(axis="y", colors="C1")
plt.show()
this is ss of output
I made circles where labels are missing. How can I fix that? Even the current labels on the x-axis aren't in their supposed positions.
I don't know the details, but it automatically determines the scale of the graph according to the number of ticks. In this case, we are skipping one. Try disabling
#ax1.set_xticklabels(df['Name of Defect'],rotation=45)and you will understand. If you specify the number of ticks for the axis you need, it will match the label and display.