Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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 3.x matplotlib中多点标记的宽度_Python 3.x_Matplotlib - Fatal编程技术网

Python 3.x matplotlib中多点标记的宽度

Python 3.x matplotlib中多点标记的宽度,python-3.x,matplotlib,Python 3.x,Matplotlib,你能帮我写下面的脚本吗?如何设置此多点打印中用于打印6个子图的刻度宽度 import numpy as np import matplotlib.pyplot as plt from numpy import array import matplotlib as mpl x = np.linspace(0, 2 * np.pi, 400) y = np.sin(x ** 2) fig, ax = plt.subplots(sharex=True) plt.figure(figsize=(12

你能帮我写下面的脚本吗?如何设置此多点打印中用于打印6个子图的刻度宽度

import numpy as np
import matplotlib.pyplot as plt
from numpy import array
import matplotlib as mpl

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

fig, ax = plt.subplots(sharex=True)
plt.figure(figsize=(12, 9))

fig1 = plt.subplot(231)
plt.plot(x, y**2)
fig1.set_xlim(0e-13,2e-13)
fig1.set_ylim(-1.15e-14,0.01e-14)
fig2=plt.subplot(232)
plt.plot(x, y**2)
fig2.set_xlim(0e-13,2e-13)
fig2.set_ylim(-7.3e-15,7.3e-15)
fig3=plt.subplot(233)
plt.plot(x, y**2)
fig3.set_ylim(0e-13,1.2e-13)
fig3.set_xlim(0e-13,2e-13)
fig4=plt.subplot(234)
plt.plot(x, y**2)
fig4.set_xlim(-1.15e-14,0.01e-14)
fig4.set_ylim(-7.3e-15,7.3e-15)
fig5=plt.subplot(235)
plt.plot(x, y**2)
fig5.set_xlim(-7.3e-15,7.3e-15)
fig5.set_ylim(0e-13,1.2e-13)
plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
fig6=plt.subplot(236)
plt.plot(x, y**2)
fig6.set_xlim(-1.5e-14,0e-14)
fig6.set_ylim(0e-13,1.2e-13)
plt.show()
我试过:

ax.xaxis.set_tick_params(width=2)
ax.yaxis.set_tick_params(width=2)


但是没有任何变化,刻度的宽度保持不变。

首先,下面是

fig, ax = plt.subplots(sharex=True)
plt.figure(figsize=(12, 9))
创建两个数字,我想你不想要

其次,当您执行
fig1=plt.subplot(231)
时,您不会创建地物对象,而是创建轴对象。此调用是多余的,因为它可以直接用
plt.subplot()
处理

第三,
ax.xaxis.set_tick_params(width=2)
在您感兴趣的图形中无效,因为ax指的是由
fig创建的轴,ax=plt.subplot(sharex=True)
而不是由
plt.figure(figsize=(12,9))
创建的当前图形中的任何轴

看看下面有没有更干净的版本

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

fig, axarr = plt.subplots(nrows=2, ncols=3)
for ax in axarr.flatten():
    ax.plot(x, y ** 2)
    ax.tick_params(width=2)
fig.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
plt.show()

谢谢您的回答。我知道我的脚本不是一个很好的脚本,但是是否可以在单独的图1部分,图2部分中写入
ax.tick_参数(宽度=2)
?好吧,如果你不想使用循环逻辑,那么在你的情况下,你必须手动为X从1到6写入
figX.tick_参数(宽度=2)
。我知道循环看起来非常紧凑,并且不清楚如何单独处理每个图。但是,如果在axarr.flatte()中为ax编写
,而不是在enumerate(axarr.flatte()):中为i,ax编写
,那么您就有了一个索引i,可以用来标识当前轴。例如,如果i==2:ax.set\u xlim((0,10))
语句成为可能,请再问一个问题?如何隐藏标签以仅显示记号?我尝试过:
labels=[item.get_text()for item in ax.get_xticklabels()]
empty_string_labels=['']*len(labels)
图1。如果您使用的是
子批次,并且您的所有子批次都具有相同的X轴和/或Y轴,将
sharex=True
和/或
sharey=True
添加到子批中即可。除此之外,常规方法是使用
勾选参数
,例如传递
labelbottom=False
。看一看,非常感谢。我有标签1,2。。。x10到2。当我使用
labelbottom=False
x10到2时,保持在那里。这个有具体的名字吗?
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)

fig, axarr = plt.subplots(nrows=2, ncols=3)
for ax in axarr.flatten():
    ax.plot(x, y ** 2)
    ax.tick_params(width=2)
fig.tight_layout(pad=0.4, w_pad=0.5, h_pad=1.0)
plt.show()