-1

I want to know how to get my x axis labels to display bigger so that the team labels aren't overlapping. I'm sure it's just a matter of configuring the chart size

My code:

plt.plot(prem_data.Team, prem_data.attack_scored,'o')
plt.plot(prem_data.Team, prem_data.defence_saves)

plt.xlabel("Team")
plt.ylabel("Attack goals scored & Defence tackles") 
plt.legend(["attack scored", "defence saved"])


plt.show()
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

I can imagine there being two mutually non-exclusive solutions.

  1. Directly alter the size of the font. This can be achieved via calling plt.rcParams.update({'font.size': <font_size>}), assuming that you have imported matplotlib.pyplot under the alias plt, as you have done in the source code provided. You would probably want to set the <font_size> to be small to prevent overlapping labels, but this would require some experimentation.

  2. Increase the size of the figure. This can be done in a number of ways, but perhaps the simplest method you can implement with minimal edits to your current code would be to use the command plt.rcParams["figure.figsize"] = <fig_size> where <fig_size> is a tuple specifying the size of the figure in inches, such as (10, 5).

With some trial and error, you should be able to manipulate the size of the font and the figure to produce a plot with improved readability.


Note: The method for altering figure size I introduced above is not the most conventional way to go about this problem. Instead, it is much more common to use matplotlib.pyplot.figure or similar variants. For more information, I recommend that you check out this thread and the documentation.

Jake Tae
  • 1,681
  • 1
  • 8
  • 11