# How to add string tick labels to 2D plots?

Hi folks, i want to add string tick labels to a 2D plot, e.g. ['$100', '$200', '$300'] on the x-axis instead of the ticks [1, 2, 3]. I see from http://stackoverflow.com/questions/5439708/python-matplotlib-creating-date-ticks-from-string that i can do this with matplotlib via from matplotlib import pyplot as plt plt.plot([1,2,3],[3,4,3]) ax = plt.gca() ax.set_xticks([1,2,3]) ax.set_xticklabels(['$100','$200','$300'])


Is there a Sage way to accomplish the same thing?

Personally, i find Sage plotting commands more user-friendly than matplotlib commands.

edit retag close merge delete

Sort by » oldest newest most voted

This functionality is not yet in sage-5.8, but will be in sage-5.9. If you want it now then simply use sage-5.9.beta1, or patch ticket 13078 into your own version of sage.

more

Is there a way to access ticks labels to rotate them? I've tried Graphics.matplotlib() and set_rotation(), but this doesn't seem to produce changes. Am I doing wrong things?

# Z is a list of [(x1,y1),(x2,y2)...]
# x1,x2 are dates
# The formatter and locator are working correctly, but the problem is all labels are oriented horizontally, messing all together. Need to rotate them
p = list_plot( Z, ticks=[10, None], tick_formatter=[dates.DateFormatter('%d.%m.%Y'), None], axes_labels=[ 'Days', '$\\log \\;{N}$' ], scale='semilogy' )

G = p.matplotlib()
labels = G.axes.xaxis.get_ticklabels()
labels = list(labels)

for label in labels:
label.set_rotation(45)

more

If you want to ask a question, I suggest that you start a new question instead of putting the question inside an answer to a question from 7 years ago.

Any help is much appreciated.

@MrDvbnhbq you can maybe delete your answer here. I added a comment under the question here to point to the question you asked.