File tree Expand file tree Collapse file tree
examples/ticks_and_spines Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33Basic demo showing how to set tick labels to values of a series.
44
55Using ax.set_xticks causes the tick labels to be set on the currently
6- chosen ticks. However, you may want to allow matplotlib to dynamically
6+ chosen ticks. However, you may want to allow matplotlib to dynamically
77choose the number of ticks and their spacing.
88
99In this case may be better to determine the tick label from the value
1616
1717"""
1818
19-
20-
2119import matplotlib .pyplot as plt
2220from matplotlib .ticker import FuncFormatter , MaxNLocator
23-
24-
2521fig = plt .figure ()
2622ax = fig .add_subplot (111 )
2723xs = range (26 )
2824ys = range (26 )
2925labels = list ('abcdefghijklmnopqrstuvwxyz' )
3026
27+
3128def format_fn (tick_val , tick_pos ):
3229 try :
3330 return labels [int (tick_val )]
3431 except IndexError :
3532 # no label for this tick
3633 return ''
37-
3834ax .xaxis .set_major_formatter (FuncFormatter (format_fn ))
3935ax .xaxis .set_major_locator (MaxNLocator (integer = True ))
40-
4136ax .plot (xs , ys )
4237plt .show ()
You can’t perform that action at this time.
0 commit comments