For questions related to the formatting of the x-axis in a plot
Questions tagged [x-axis]
332 questions
881
votes
12 answers
How do I set the figure title and axes labels font size?
I am creating a figure in Matplotlib like this:
from matplotlib import pyplot as plt
fig = plt.figure()
plt.plot(data)
fig.suptitle('test title')
plt.xlabel('xlabel')
plt.ylabel('ylabel')
fig.savefig('test.jpg')
I want to specify font sizes for…

vasek1
- 13,541
- 11
- 32
- 36
652
votes
9 answers
How to set the axis limits
I need help with setting the limits of y-axis on matplotlib. Here is the code that I tried, unsuccessfully.
import matplotlib.pyplot as plt
plt.figure(1, figsize = (8.5,11))
plt.suptitle('plot title')
ax = []
aPlot = plt.subplot(321, axisbg = 'w',…

Curious2learn
- 31,692
- 43
- 108
- 125
268
votes
9 answers
Rotate label text in seaborn
I have a simple factorplot
import seaborn as sns
g = sns.factorplot("name", "miss_ratio", "policy", dodge=.2,
linestyles=["none", "none", "none", "none"], data=df[df["level"] == 2])
The problem is that the x labels all run together, making…

dan
- 4,262
- 7
- 25
- 40
213
votes
5 answers
Plotting time on the independent axis
I have an array of timestamps in the format (HH:MM:SS.mmmmmm) and another array of floating point numbers, each corresponding to a value in the timestamp array.
Can I plot time on the x axis and the numbers on the y-axis using Matplotlib?
I was…

randomThought
- 6,203
- 15
- 56
- 72
49
votes
2 answers
How to add group labels for bar charts
I want to plot data of the following form, using matplotlib bar plot:
data = {'Room A':
{'Shelf 1':
{'Milk': 10,
'Water': 20},
'Shelf 2':
{'Sugar': 5,
'Honey': 6}
…

Varicus
- 1,523
- 2
- 12
- 12
39
votes
5 answers
Setting the same axis limits for all subplots
This problem seems simple enough, but I can't find a pythonic way to solve it. I have several (four) subplots that are supposed to have the same xlim and ylim. Iterating over all subplots à la
f, axarr = plt.subplots(4)
for x in range(n):
…

MrArsGravis
- 568
- 1
- 4
- 9
35
votes
5 answers
Fixing x axis scale and autoscale y axis
I would like to plot only part of the array, fixing the x part, but letting the y part autoscale. I tried as shown below, but it does not work.
Any suggestions?
import numpy as np
import matplotlib.pyplot as…

Pygmalion
- 785
- 2
- 8
- 24
32
votes
2 answers
What is the difference between set_xlim and set_xbound?
From the help:
set_xlim: Set the data limits for the xaxis.
set_xbound: Set the lower and upper numerical bounds of the x-axis.
That is not very clear, so let’s say that I plot something:
import matplotlib.pylab as plt
fig, ax = plt.subplots(1,…

PhML
- 1,190
- 1
- 11
- 20
31
votes
5 answers
Multiple lines of x tick labels
I'm trying to make a plot similar to this excel example:
I would like to know if there is anyways to have a second layer on the x tick labels (e.g. "5 Year Statistical Summary"). I know I can make multi-line tick labels using \n but I want to be…

HHains
- 683
- 2
- 9
- 17
20
votes
2 answers
Diagonal tick labels
I am plotting a bar chart in python using matplotlib.pyplot. The chart will contain a large number of bars, and each bar has its own label. Thus, the labels overlap, and they are no more readable. I would like that the label are displayed diagonally…

Marco
- 3,053
- 5
- 27
- 29
15
votes
1 answer
Individually labeled bars for bar graphs
I am trying to create bar graphs of letter frequency in Python. I thought the best way to accomplish this would be matplotlib, but I have been unable to decipher the documentation. Is it possible to label the bars of a matplotlib.pyplot.hist plot…

josePhoenix
- 538
- 1
- 5
- 14
12
votes
2 answers
Remove some xtick labels from a seaborn plot
In the screenshot below, all my x-labels are overlapping each other.
g = sns.factorplot(x='Age', y='PassengerId', hue='Survived', col='Sex', kind='strip', data=train);
I know that I can remove all the labels by calling g.set(xticks=[]), but is…

Huey
- 2,714
- 6
- 28
- 34
10
votes
4 answers
How to plot without extending axis limits
I'm trying to draw on an existing axis without extending or modifying its limits.
For example:
import numpy as np
import matplotlib.pyplot as plt
xy = np.random.randn(100, 2)
plt.scatter(xy[:,0], xy[:,1])
Makes a fine plot with well-fitting axis…

shadowtalker
- 12,529
- 3
- 53
- 96
10
votes
2 answers
Remove axis label offset by default
I've read other questions here offering
plt.gca().get_xaxis().get_major_formatter().set_useOffset(False)
as a way to remove axis offsets on the current plot, but is there any way to do this by default? I don't see anything in the matplotlibrc file…
user2297781
9
votes
2 answers
Hierarchical axis labeling
Suppose I'm looking at an n x n grid and on each axis I have labels of say, animals. But I'm also interested at looking at the relationship between groups, subgroups, etc. of the animals. So for example, I may have vertebrates and invertebrates,…

C S
- 1,363
- 1
- 17
- 26