简体   繁体   English

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

[英]How can I add more ticks between x-axis or y-axis labels using python?

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? 在这里你找到我的代码..基本上,python默认返回一个带有x-ticks标签的图,如4,6,8 ...我想要的是有4,5,6,7,8 ..有帮助吗? 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)
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) . 这表明你应该尝试像plt.xticks(range(round(d20[-1])+2), size=size)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Plotly Python 中移动 x 轴和 y 轴刻度 - Moving the x-axis and y-axis ticks in Plotly Python 如何更改 plotly 中的 x 轴和 y 轴标签? - How to change the x-axis and y-axis labels in plotly? 熊猫:如何在1到12月的月份中标记x轴上的刻度线,并限制y轴上的范围? - Pandas: How can I label ticks on x-axis with months from Jan to Dec and limit the range on the y-axis? 如何在 python 中以像素数为 x 轴,灰度颜色为 y 轴 plot 图形? - How can I plot the figure with the number of pixel as a x-axis and the grayscale color as a y-axis in python? 如何使用Python的Bokeh向日期时间轴添加更多x轴刻度和标签? - How do you add more x axis ticks and labels to datetime axis using Python's Bokeh? 如何在 matplotlib 中设置自定义 x 轴和 y 轴刻度? - How to set custom x-axis and y-axis ticks in matplotlib? Python和plot():如何限制x轴刻度(标签)的数量 - Python and plot() : how to limit the number of x-axis ticks (labels) 如何使用 plot 在 x 轴上循环变量 i 和在 y 轴上循环中的局部变量使用 matplotlib - How to plot loop variable i on x-axis and local variable in the loop on y-axis using matplotlib 在日志中修复 x 轴和 y 轴 plot python - Fixing x-axis and y-axis in a log plot python 在python中具有不同x轴和y轴刻度的两个(或更多)图 - two (or more) graphs in one plot with different x-axis AND y-axis scales in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM