Ask Your Question

How to add string tick labels to 2D plots?

asked 2013-03-24 18:48:21 +0200

araichev gravatar image

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 that i can do this with matplotlib via

from matplotlib import pyplot as plt
ax = plt.gca()

Is there a Sage way to accomplish the same thing?

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

edit retag flag offensive close merge delete


For reference, a related question was later asked:

slelievre gravatar imageslelievre ( 2020-04-28 18:56:25 +0200 )edit

2 Answers

Sort by » oldest newest most voted

answered 2013-03-24 21:05:01 +0200

ppurka gravatar image

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.

edit flag offensive delete link more

answered 2020-04-27 10:12:22 +0200

MrDvbnhbq gravatar image

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[0].xaxis.get_ticklabels()
labels = list(labels)

for label in labels:
edit flag offensive delete link 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.

Sébastien gravatar imageSébastien ( 2020-04-27 20:20:15 +0200 )edit

If that would be a better way to ask questions,

Any help is much appreciated.

MrDvbnhbq gravatar imageMrDvbnhbq ( 2020-04-27 21:08:44 +0200 )edit

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

slelievre gravatar imageslelievre ( 2020-04-28 18:57:35 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-03-24 18:48:21 +0200

Seen: 1,670 times

Last updated: Apr 27 '20