1

在这里您可以找到我的代码.. 基本上,python 默认情况下会返回一个带有 x-ticks 标签的图,例如 4,6,8...,而我想要的是 4,5,6,7,8..有什么帮助吗?非常感谢!!

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)
4

1 回答 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 )

这建议您应该尝试类似plt.xticks(range(round(d20[-1])+2), size=size).

于 2012-06-18T11:52:44.827 回答