If I create a plot with matplotlib using the following code:
import numpy as np from matplotlib import pyplot as plt xx = np.arange(0,5, .5) yy = np.random.random( len(xx) ) plt.plot(xx,yy) plt.imshow()
I get a result that looks like the attached image. The problem is the bottom-most y-tick label overlaps the left-most x-tick label. This looks unprofessional. I was wondering if there was an automatic way to delete the bottom-most y-tick label, so I don't have the overlap problem. The fewer lines of code, the better.
Matplotlib x-axis label overlap In matplotlib, we have a method setp() that is used to set the rotation and alignment attributes of tick labels to avoid overlapping. To get ticklabels, we use the plt. setp() and get.
Use legend() method to avoid overlapping of labels and autopct. To display the figure, use show() method.
0 A common problem in making plots, say a barplot or boxplot with a number of groups is that, names of the groups on x-axis label often overlap with each other. Till now, one of the solutions to avoid overlapping text x-axis is to swap x and y axis with coord_flip() and make a horizontal barplot or boxplot.
With Pyplot, you can use the xlabel() and ylabel() functions to set a label for the x- and y-axis.
In the ticker module there is a class called MaxNLocator that can take a prune
kwarg.
Using that you can remove the first tick:
import matplotlib.pyplot as plt from matplotlib.ticker import MaxNLocator import numpy as np xx = np.arange(0,5, .5) yy = np.random.random( len(xx) ) plt.plot(xx,yy) plt.gca().xaxis.set_major_locator(MaxNLocator(prune='lower')) plt.show()
Result:
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