1

Here you find my code.. basically, python returns me by default a plot with x-ticks labels like 4,6,8... and what I want is to have something like 4,5,6,7,8.. Any help? Thanks very much!!

from mpl_toolkits.axes_grid.parasite_axes import SubplotHost
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure(1)
host = SubplotHost(fig, 111)
fig.add_subplot(host)
c13=[1.79, 2.15, 3.81, 6.12, 8.28, 7.93, 8.07, 8.88]
c13014=[3.12, 3.28, 4.57, 7.24, 8.37, 9.26, 8.24, 8.25]
C13dflow=[0., 0., 0., 0., 8.06, 8.13]
d20=[5, 7, 8, 9, 10, 11, 12, 13]
d20low=[5, 7, 8, 10, 11, 13]
host.plot(d20, c13, 'ro')
host.plot(d20, c13, 'r-', label='f1=0.01 (0.09 in TDU)')
host.plot(d20, c13014, 'bo')
host.plot(d20, c13014, 'b--', label='f1=0.014 (0.126 in TDU)')
host.plot(d20low, C13dflow, 'go')
host.plot(d20low, C13dflow, 'g-.', label='f1=0.01 (0.01 in TDU)')
host.axis([4., 14., 0., 10.])
legend(loc=2)
plt.ylabel('$^{13}C$ pocket mass [10ドル^{-5}$ $M_{\odot}$]', fontsize=27)
plt.xlabel('Log(D20) [$cm^{2}$/s]', fontsize=27)
plt.title('Max $^{13}C$ pocket masses using double-f overshooting ', fontsize=27)
size=20
plt.xticks(size=size)
plt.yticks(size=size)
host.toggle_axisline(False)
host.grid(True)
asked Jun 18, 2012 at 11:44
1
  • It would be nice to include the graphical output of your script with your question. Commented Apr 26, 2013 at 14:22

1 Answer 1

3
In [1]: import matplotlib.pyplot as plt
In [2]: plt.xticks?
Type: function
Base Class: <type 'function'>
String Form:<function xticks at 0x2c1e050>
Namespace: Interactive
File: /usr/lib/pymodules/python2.7/matplotlib/pyplot.py
Definition: plt.xticks(*args, **kwargs)
Docstring:
Set/Get the xlimits of the current ticklocs and labels::
 # return locs, labels where locs is an array of tick locations and
 # labels is an array of tick labels.
 locs, labels = xticks()
 # set the locations of the xticks
 xticks( arange(6) )
 # set the locations and labels of the xticks
 xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
The keyword args, if any, are :class:`~matplotlib.text.Text`
properties. For example, to rotate long labels::
 xticks( arange(12), calendar.month_name[1:13], rotation=17 )

This suggests you should try something like plt.xticks(range(round(d20[-1])+2), size=size).

answered Jun 18, 2012 at 11:52

2 Comments

Thanks very much! That was a very useful hint.. in the end I fixed the problem using simply: xticks = np.arange(4,14,1)// plt.xticks(xticks)// plt.xticks(size=size)
@Umberto that works as long as you know exactly what range you need. I just wanted to give an idea of what to do when it's not the case. Anyway, glad to help. If you believe the problem is resolved, consider accepting the answer.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.