Questions tagged [xticks]

For questions related to xticks in matplotlib, seaborn, or pandas plots.

"xticks" refers mainly to a submodule of the python plotting library matplotlib which handels the ticks of the x axis. But this tag is in general not limited to python or matplotlib but can be used whenever one refers to position and appearance of ticks and marks at the axes of a graph.

255 questions
753
votes
14 answers

Changing the tick frequency on the x or y axis

I am trying to fix how python plots my data. Say: x = [0, 5, 9, 10, 15] y = [0, 1, 2, 3, 4] matplotlib.pyplot.plot(x, y) matplotlib.pyplot.show() The x axis' ticks are plotted in intervals of 5. Is there a way to make it show intervals of 1?
Dax Feliz
  • 12,220
  • 8
  • 30
  • 33
482
votes
12 answers

How to remove xticks from a plot

I have a semilogx plot and I would like to remove the xticks. I tried: plt.gca().set_xticks([]) plt.xticks([]) ax.set_xticks([]) The grid disappears (ok), but small ticks (at the place of the main ticks) remain. How to remove them?
Vincent
  • 57,703
  • 61
  • 205
  • 388
310
votes
13 answers

Modify tick label text

I want to make some modifications to a few selected tick labels in a plot. For example, if I do: label = axes.yaxis.get_major_ticks()[2].label label.set_fontsize(size) label.set_rotation('vertical') the font size and the orientation of the tick…
repoman
  • 3,485
  • 2
  • 16
  • 15
247
votes
6 answers

Date ticks and rotation

I am having an issue trying to get my date ticks rotated in matplotlib. A small sample program is below. If I try to rotate the ticks at the end, the ticks do not get rotated. If I try to rotate the ticks as shown under the comment 'crashes', then…
Neal
  • 6,722
  • 4
  • 38
  • 31
124
votes
3 answers

Change grid interval and specify tick labels

I am trying to plot counts in gridded plots, but I haven't been able to figure out how to go about it. I want: to have dotted grids at an interval of 5; to have major tick labels only every 20; for the ticks to be outside the plot; and to have…
owl
  • 1,841
  • 6
  • 20
  • 30
99
votes
8 answers

Format axis offset-values to whole numbers or specific number

I have a matplotlib figure which I am plotting data that is always referred to as nanoseconds (1e-9). On the y-axis, if I have data that is tens of nanoseconds, ie. 44e-9, the value on the axis shows as 4.4 with a +1e-8 as an offset. Is there…
Jonathan
  • 1,205
  • 1
  • 10
  • 12
99
votes
5 answers

How to force integer tick labels

My python script uses matplotlib to plot a 2D "heat map" of an x, y, z dataset. My x- and y-values represent amino acid residues in a protein and can therefore only be integers. When I zoom into the plot, it looks like this: As I said, float values…
gha
  • 3,459
  • 3
  • 18
  • 13
88
votes
4 answers

Editing the date formatting of x-axis tick labels

I am looking to edit the formatting of the dates on the x-axis. The picture below shows how they appear on my bar graph by default. I would like to remove the repetition of 'Dec' and '2012' and just have the actual date numbers along the x-axis. Any…
Osmond Bishop
  • 7,560
  • 14
  • 42
  • 51
88
votes
3 answers

Pandas timeseries plot setting x-axis major and minor ticks and labels

I want to be able to set the major and minor xticks and their labels for a time series graph plotted from a Pandas time series object. The Pandas 0.9 "what's new" page says: "you can either use to_pydatetime or register a converter for…
brenda
  • 998
  • 1
  • 7
  • 8
79
votes
3 answers

How can I rotate xticklabels in so the spacing between each xticklabel is equal?

How can I rotate xticklabels in matplotlib so that the spacing between each xticklabel is equal? For example with this code: import matplotlib.pyplot as plt import numpy as np # Data + parameters fontsize = 20 t = np.arange(0.0, 6.0,…
Franck Dernoncourt
  • 77,520
  • 72
  • 342
  • 501
41
votes
5 answers

Matplotlib semi-log plot: minor tick marks are gone when range is large

When making a semi-log plot (y is log), the minor tick marks (8 in a decade) on the y axis appear automatically, but it seems that when the axis range exceeds 10**10, they disappear. I tried many ways to force them back in, but to no avail. It might…
Chuck
  • 413
  • 1
  • 4
  • 4
32
votes
1 answer

Change tick frequency on X (time, not number) frequency

My python plot data only show 2 points on x axis. I would like to have more, but don't know how. x = [ datetime.datetime(1900,1,1,0,1,2), datetime.datetime(1900,1,1,0,1,3), ... ] # ( more…
Kensg
  • 321
  • 1
  • 3
  • 3
19
votes
3 answers

Matplotlib - Changing the color of a single x-axis tick label

I am trying to create a vertical bar chart of % speakers of 5 spoken languages in the world, using matplotlib. To better accentuate the highest spoken language, I have changed the color of the bar. I also want to change the corresponding x-axis…
Doug B
  • 347
  • 1
  • 2
  • 8
13
votes
2 answers

X-axis tick labels are too dense when drawing plots

I am drawing matplotlib plots and my x axis consists of YYYYMM formatted strings of year and month like 201901 for January of 2019. My problem is that some of the data spans on a long period of time and this makes the x axis tick labels so dense…
Canol Gökel
  • 1,168
  • 2
  • 13
  • 29
9
votes
1 answer

Position of bar plot xtick labels have irregular spaces

I'm trying to do a bar plot for many countries and i want the names displayed a bit rotated underneath the bars. The problem is that the spaces between the labels are irregular. Here's the relevant code: plt.bar(i, bar_height, align='center',…
Christian Kaiser
  • 160
  • 1
  • 1
  • 10
1
2 3
16 17