Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python在x轴或y轴标签之间添加更多标记?_Python_Matplotlib - Fatal编程技术网

如何使用python在x轴或y轴标签之间添加更多标记?

如何使用python在x轴或y轴标签之间添加更多标记?,python,matplotlib,Python,Matplotlib,在这里你可以找到我的代码。。基本上,python在默认情况下返回一个带有x记号标签的绘图,如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.ad

在这里你可以找到我的代码。。基本上,python在默认情况下返回一个带有x记号标签的绘图,如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)
[1]中的
:将matplotlib.pyplot作为plt导入
在[2]:plt.xticks?
类型:功能
基类:
字符串形式:
名称空间:交互式
文件:/usr/lib/pymodules/python2.7/matplotlib/pyplot.py
定义:plt.xticks(*args,**kwargs)
文档字符串:
设置/获取当前标记和标签的xlimits::
#返回LOC,其中LOC是标记位置数组的标签,以及
#标签是一组记号标签。
LOC,标签=xticks()
#设置XTICK的位置
xticks(阿兰奇(6))
#设置XTICK的位置和标签
xticks(arange(5),('Tom','Dick','Harry','Sally','Sue'))
关键字args(如果有)是:class:`~matplotlib.text.text`
财产。例如,要旋转长标签,请执行以下操作:
xticks(arange(12),日历,月名[1:13],轮换=17)

这建议您应该尝试类似于
plt.xticks(范围(圆形(d20[-1])+2),大小=大小)

非常感谢!那是一个非常有用的提示。。最后,我简单地使用:xticks=np.arange(4,14,1)//plt.xticks(xticks)//plt.xticks(size=size)@Umberto解决了这个问题,只要您知道所需的范围就可以了。我只是想给你一个主意,如果情况不是这样的话该怎么办。不管怎样,我很乐意帮忙。如果你认为问题已经解决了,考虑一下,把你的脚本的图形输出和你的问题结合起来是很好的。
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 )