markov zain
markov zain

Reputation: 12905

How to adjust the distance between y-axis label in python

I have a code to make a chart following below:

%pylab inline
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
matplotlib.use('TkAgg')
plt.style.use('ggplot')
dataframe.T.plot(kind='barh', stacked=True)
plt.xticks(np.arange(0, 1.1, 0.1), [str(x) for x in np.arange(0, 1.1, 0.1)])
plt.xlim([0, 1])
plt.xlabel("Pecentage of Interets")
plt.ylabel("Users")
plt.legend(loc=9, bbox_to_anchor=(0.5, -0.2), ncol=7)
plt.savefig('personint.jpg', format='eps', dpi=1000, bbox_inches='tight')

the results of my code is like this:

enter image description here

In here, I want to ask how I can adjust the distance between y-axis label in my code, such as space between USER1 and USER2, because the distance for each user in my chart is close to each other.

Upvotes: 0

Views: 3407

Answers (1)

ODiogoSilva
ODiogoSilva

Reputation: 2414

You will need to add more vertical space to the figure, so try changing the figure size at the beginning of your code with:

plt.rcParams["figure.figsize"] = (8, 10)

The vertical space can also change dynamically with the number of y-axis labels.

# labels = ["USER1", "USER2", ...]
plt.rcParams["figure.figsize"] = (8, 6 * len(labels) / 10)

Just change the division denominator to adjust the amount of space you want to give.

Upvotes: 1

Related Questions