Ask Your Question
0

How to add string tick labels to 2D plots?

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

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 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 flag offensive close merge delete

Comments

For reference, a related question was later asked:

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

2 Answers

Sort by » oldest newest most voted
2

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

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
0

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

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:
    label.set_rotation(45)
edit flag offensive delete link more

Comments

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 +0100 )edit

If that would be a better way to ask questions, https://ask.sagemath.org/question/51080/how-to-change-ticks-labels-attributes-for-the-2d-plot/

Any help is much appreciated.

MrDvbnhbq gravatar imageMrDvbnhbq ( 2020-04-27 21:08:44 +0100 )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 +0100 )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

Stats

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

Seen: 2,286 times

Last updated: Apr 27 '20