【问题标题】:matplotlib how to plot semilog graph with yticks and horizontal grid lines spaced logarithmicallymatplotlib如何绘制带有对数间隔的yticks和水平网格线的半对数图
【发布时间】:2015-04-20 20:58:06
【问题描述】:

我想在 20000 到 50000 范围内绘制一些 y 数据。

我希望 y 轴以 5000 的步长从 10000 变为 60000。
我希望 y 轴是对数图。

我试过ax1.set_yscale('log')。这给出了一个对数图,但没有水平网格线,也没有 y 刻度。

我如何获得两个方向的网格线和 y 刻度上升 10000、15000 等,并具有对数间距?

我正在尝试获得这样的 yaxis 比例

我在 Python 2.5.2 中使用以下代码:

fig = pl.figure()
rcParams['figure.figsize'] = 14, 10 # set graph size
ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(do,line,'r-', do,ind,'g-')  
ax1.grid(True)
pl.xticks(do,rotation=45)
ax1.set_xlim( [date1, date2] )
ax1.set_yscale('log')
pl.show()

我可以计算 log(line)log(ind) 并绘制线性图,但该图信息量不大!

【问题讨论】:

  • 点击链接时看不到图片。可以直接放在这里而不是链接吗?
  • 查看gallery中的示例
  • hmmm ......是的,链接不可点击!我不得不复制并粘贴它 - 抱歉
  • 我查看了图库,示例使用 10 次方的数字,例如 10 到 10000。它们不使用 10 到 60 等较小范围内的数字
  • 这是一个类似的图表;希望可以点击bigcharts.marketwatch.com/kaavio.Webhost/charts/…

标签: python logging matplotlib plot python-2.5


【解决方案1】:

您可能需要打开次要网格。但也要注意,对于对数图,从 10 到 60 的范围非常小(这就是没有出现主网格的原因)

import pylab as pl
fig = pl.figure()
# rcParams['figure.figsize'] = 14, 10 # set graph size
ax1 = fig.add_subplot(1, 1, 1)
#ax1.plot(line,'r-', ind,'g-')
ax1.grid(True)
# pl.xticks(do,rotation=45)
ax1.set_xlim([10, 20])
ax1.set_yscale('log')
ax1.set_ylim([10000, 60000])
ax1.grid(which='minor')
pl.show()

【讨论】:

【解决方案2】:

感谢大家的关注。在阅读了您的建议和 Beachcombers 链接以及一些实验之后,我想出了以下解决方案。

import pylab as pl
fig = pl.figure()
rcParams['figure.figsize'] = 14, 10 # set graph size
ax1 = fig.add_subplot(1, 1, 1)
ax1.plot(do,line,'r-', do, ind,'g-')
ax1.grid(True)
pl.xticks(do,rotation=45)
ax1.set_xlim( [date1, date2] )
ax1.set_yscale('log')
ax1.grid(which='minor')
from matplotlib.ticker import FormatStrFormatter
ax1.yaxis.set_minor_formatter(FormatStrFormatter("%.0f"))
pl.show()

【讨论】:

    猜你喜欢
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2018-10-29
    • 2018-01-29
    • 2016-01-27
    相关资源
    最近更新 更多