相关疑难解决方法(0)

在matplotlib中制作更长的子图刻度标记?

我试图改变沿python多面板子图的轴的刻度线.我有两个共用一个x轴的面板.我已经使绘图周围的边框更粗,并使沿轴的所有刻度线更粗.我有两个问题:

如何使所有刻度线(两个轴)更长,以便更加明显?

如何在主要刻度线之间添加较小但仍然明显的刻度线?

这是我到目前为止的最低工作示例.

from numpy import *
from scipy import *
from pylab import *
from random import *
import pylab
import matplotlib.pyplot as plt


#make the axis border thick
pylab.rc("axes", linewidth=4.0)
pylab.rc("lines", markeredgewidth=4)


#create a figure with two panels that shares the x-axis
f, (ax1, ax2) = plt.subplots(2, sharex=True, sharey=False)
#example figure1
ax1.plot(range(2),range(2),linewidth=2)
#example figure 2
ax2.plot(range(2),range(2),linewidth=2)



# Fine-tune figure; make subplots close to each other and hide x ticks for
# all but bottom plot.
f.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() …
Run Code Online (Sandbox Code Playgroud)

python matplotlib subplot

19
推荐指数
1
解决办法
1万
查看次数

使用刺来定制matplotlib中刻度线的一侧

我有一个matplotlib水平条绘制如下:

import matplotlib.pyplot as plt
from numpy import *
from scipy import *
bars = arange(5) + 0.1
vals = rand(5)
print bars, vals
plt.figure(figsize=(5,5), dpi=100)
spines = ["bottom"]
ax = plt.subplot(1, 1, 1)
for loc, spine in ax.spines.iteritems():
  if loc not in spines:
    spine.set_color('none')
# don't draw ytick marks
#ax.yaxis.set_tick_params(size=0)
ax.xaxis.set_ticks_position('bottom')
plt.barh(bars, vals, align="center")
plt.savefig("test.png") 
Run Code Online (Sandbox Code Playgroud)

这会产生这个图像:在此输入图像描述

我想只显示使用刺的xaxis,但现在它为右手yaxis绘制了这些悬挂的标记.我怎样才能删除这些?我喜欢将ytickmarks保留在绘图的左侧,并使它们面朝外(与条形相反的方向).我知道我可以通过取消注释该行来完全删除ytickmarks:

#ax.yaxis.set_tick_params(size=0)
Run Code Online (Sandbox Code Playgroud)

但我想只在左侧保留ytick标记.谢谢.

编辑:我经过一些试验和错误后实现了一个解决方案,虽然我确定我的解决方案可能不是最好的方法,所以请让我知道你的想法.我发现我能做到:

ax.spines["left"].axis.axes.tick_params(direction="outward") 
Run Code Online (Sandbox Code Playgroud)

设置刻度标记方向.为了摆脱正确的y轴刻度,我使用:

ax.yaxis.set_ticks_position("left")
Run Code Online (Sandbox Code Playgroud)

python numpy matplotlib scipy

10
推荐指数
2
解决办法
1万
查看次数

标签 统计

matplotlib ×2

python ×2

numpy ×1

scipy ×1

subplot ×1