
# set ticks visible, if using sharex = True. # Set the formatting the same for both subplotsĪxes.tick_params(axis='both', which='both', labelsize=7) Pd.set_option('display.width', desired_width)ĭf = pd.DataFrame()ĭf.index = (pd.to_datetime(df.index)).strftime("%m/%d %H:00")įig, axes = plt.subplots(nrows=2, ncols=1, sharex=True)ĭf.groupby('State').plot(kind='line', linestyle='-', alpha=0.5, marker='o', legend=True, ax=axes) If you’re working with a single plot, you can use the () function to rotate the labels on the x-axis, pass the degree of rotation to the rotation parameter. As can be seen in the picture, only 106 is displayed on the x-axis, but I need values for other.

Firstly, you can change it on the Figure-level with plt.yticks (), or on the Axes-level by using trotation () or by manipulating the ax.setyticklabels () and ax.tickparams ().
Matplotlib subplot rotate tick labels how to#
Firstly, you can change it on the Figure-level with plt. Example 1: Rotate X-Axis Tick Labels The following code shows how to rotate the x-axis tick labels in Matplotlib: import matplotlib.pyplot as plt define data x 1, 2, 3, 4 y 7, 13, 24, 22 create plot plt.plot(x, y, color'red') rotate x-axis tick labels plt.

Can you please help in displaying the y-label on both subplots?īelow is my reproducible code. I did that using this command: import matplotlib as plt plt.plot (X,Y) plt.xscale ('log') The x-axis is logarithmic, but only values which are multiples of 10 are displayed in the graph, but I need values for all gridlines to be shown in the graph. Rotate Y-Axis Tick Labels in Matplotlib The exact same steps can be applied for the Y-Axis tick labels. The exact same steps can be applied for the Y-Axis tick labels.

How can I make the x-ticks visible on both subplots?Īlso I would like to set y-labels for both subplots but only the second is visible. import matplotlib.pyplot as plt x 1, 2, 3, 4 y 1, 4, 9, 6 labels Frogs, Hogs, Bogs, Slogs plt. I am plotting two subplots that share the same x-axis but when I plot I only see the x-axis ticks on the second subplot.
