Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hexadecimal X-axis in matplotlib?

Is it possible to somehow have the values on the X-axis be printed in hexadecimal notation in matplotlib? For my plot the X-axis represents memory addresses.

Thanks.

like image 304
user3207230 Avatar asked Jan 17 '14 15:01

user3207230


1 Answers

You can set a Formatter on the axis, for example the FormatStrFormatter.

Simple example :

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker


plt.plot([10, 20, 30], [1, 3, 2])
axes = plt.gca()
axes.get_xaxis().set_major_locator(ticker.MultipleLocator(1))
axes.get_xaxis().set_major_formatter(ticker.FormatStrFormatter("%x"))
plt.show()
like image 114
remram Avatar answered Oct 02 '22 17:10

remram