python - 绘图中的网格更平滑

标签 python matplotlib

我正在尝试在已经绘制的网格的背景中绘制更平滑的网格。这就是我到目前为止所做的。网格遵循我的主要刻度。我希望这个更平滑的网格能够跟随小刻度。这可能吗?

到目前为止我的代码:

fig, ax = plt.subplots(figsize = (20,10))

ax.set_xticks(np.arange(0,round(max(datax)+1)))
ax.set_yticks(np.arange(0,round(max(datay)+1),step = 0.1))
ax.minorticks_on()
ax.grid(True)
plt.xlabel("Tensão (V)", fontsize = 14)
plt.ylabel("Corrente (mA)", fontsize = 14)
plt.title("Experimento 2", fontsize = 20)
ax.errorbar(datax,datay,xerr = sigmax, yerr = sigmay, fmt = ',')
ax.set(xlim= -1, ylim = 0)

P.S.:你们会以不同的方式组织这段代码吗?我认为这完全是一团糟。

i want my grids to look like this this is how they are now

最佳答案

您需要的是 gridlinestyle 关键字参数,以及 linewidth 关键字参数。

以下是如何使用虚线作为网格,并使用较细的线作为小刻度:

ax.grid(True, which='major', linestyle=':', linewidth=1, color="black")
ax.grid(True, which='minor', linestyle=':', linewidth=0.5, color="black")

这是输出(我使用了伪造的数据,因为您没有提供 MWE):

enter image description here

您可以调整 linewidth 参数让线条显得更细,或者调整 color 参数让线条变得更淡。 您还可以尝试其他线条样式,例如虚线 (linestyle='--')。

关于python - 绘图中的网格更平滑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57564728/

相关文章:

python - 一次在数据框列上应用多个函数

python - 只读字段没有保存在openerp的数据库中?

Python tkinter 不会显示对角线

python - grid zorder 好像没有生效(matplotlib)

python - plt.cm.get_cmap 中可以使用哪些名称?

Python - 基于计时器更新绘图

python - 如何可视化Caffe参数?

python - 使用 Python 中的斯坦福 CoreNLP 进行情感分析

python - 如何异或两个十六进制字符串,以便每个字节分别异或?

python - matplotlib:将小时字符串转换为 float