How to move labels from bottom to top without adding "ticks"
15,138
Solution 1
Try this:
plt.tick_params(axis='both', which='major', labelsize=10, labelbottom = False, bottom=False, top = False, labeltop=True)
the parameter top=False means no ticks. :)
Solution 2
Ok finally found.
Needs a
ax.tick_params(length=0)
Related videos on Youtube
![Kalanit](https://i.stack.imgur.com/LQSpI.jpg?s=256&g=1)
Author by
Kalanit
Updated on June 08, 2022Comments
-
Kalanit about 2 years
How can I position xlabel on top of the plot using something else than "tick_top" - that adds a tick to the x label, and I don't want it.
xlabel on the bottom with no tick:
code:
import numpy as np; np.random.seed(0) import matplotlib.pyplot as plt import seaborn as sns sns.set() uniform_data = np.random.rand(10, 12) ax = sns.heatmap(uniform_data, vmin=0, vmax=1) plt.yticks(rotation=0) plt.show()
code:
import numpy as np; np.random.seed(0) import matplotlib.pyplot as plt import seaborn as sns sns.set() uniform_data = np.random.rand(10, 12) ax = sns.heatmap(uniform_data, vmin=0, vmax=1) plt.yticks(rotation=0) ax.xaxis.tick_top() # x axis on top ax.xaxis.set_label_position('top') plt.show()
-
Mad Physicist almost 6 yearsCan you do
set_label_position
withouttick_top
? -
Kalanit almost 6 yearsI can, but then the xlabels stay on the bottom...
-
Mad Physicist almost 6 yearsHow about get rid of tick_top and use set_tick_position instead of set_label_position?
-
Mad Physicist almost 6 yearsDoes this work: stackoverflow.com/q/14406214/2988730?
-
Kalanit almost 6 yearsNo it didnt work.
-
-
Albert Chen almost 4 yearsFYI, it is also applied to ax.tick_params(...)