在绘制数据时,我希望能够控制子地块的主刻度和次刻度。然而,无论我尝试什么,我似乎都无法修改我的第二个子批的滴答声。我尝试过应用其他stackoverflow问题的建议,但不幸的是没有用。我认为我在构建箱线图时犯了一些根本错误
由于我的同事中没有人对matplotlib有太多的经验,所以我要向你们求助!任何帮助都将不胜感激
目前,我的数据如下:
在第二个箱线图上,我还希望每隔10^X强制一个主刻度,并显示默认的日志次刻度
目前,我生成的箱线图如下所示:
def generateLogBoxPlot(title, plot_id, xlabels, data, initializion_time, fig):
# Create an axes instance
ax = fig.add_subplot(plot_id)
# Set Log Scale
ax.set_yscale('log')
# Create the boxplot
bp = ax.boxplot(data_of_plot)
# Show Initialization Time (as a Line)
line = plt.plot(...)
# Custom rotated x-axis labels
ax.set_xticklabels(xlabels)
plt.xticks(rotation=15)
#Set Labels
plt.ylabel('Time (ms)')
ax.set_title(title)
#Show Grid
ax.get_yaxis().grid()
我这样称呼这个函数:
# Create a figure instance
fig = plt.figure(1, figsize=(9, 3))
# Generate first subplot
generateLogBoxPlot("No Context-Dependent A.C.\nBusiness Case", #title
121, #plot_id
["Add User", "Add Role", "Add Demarcation", "Add Permission"], #labels
results["AddEntities"], #data
40000, #initializion_time
fig) #figure
line = generateLogBoxPlot("Context-Dependent A.C.\nBusiness Case",
122, #plot_id
["Add User", "Add Role", "Add Demarcation", "Add Permission"], #labels
results["AddEntities2"], #data
153000, #initialization_time
fig) #figure
#Show Legend
plt.legend(plt.plot([], [],linestyle="--", color="#A9A9A9", label="Initialization
Time"),["Initialization Time"], loc='center left', bbox_to_anchor=(1, 0.5))
#Show
plt.tight_layout()
plt.show()
无论我尝试什么,我似乎只能修改fist子地块的滴答声。如何在第二个子地块上强制/编辑它们
Matplotlib根据值的范围以及在某种程度上的地物大小,自动显示或隐藏对数刻度的小刻度。关于y轴基准10对数刻度,以下是我在测试下面所示示例的变化时注意到的内容(使用matplotlib 3.3.2和默认设置):
对于您的特定示例,在任何情况下,我都会从共享y轴开始,以使绘图更具可比性。然后剩下两个选项:要么保留默认的记号格式,不使用小记号,要么强制两个绘图都使用小记号
matplotlib默认日志勾选行为的示例以及如何更改它
首先,以下是带有日志标记的matplotlib默认行为的示例:
现在,如果图形高度增加,为刻度留出更多空间,该怎么办
这个特殊的例子表明,增加图形大小可以解决小刻度不显示的问题,但情况往往并非如此
下面是如何通过使用来自^{} 模块的^{} 强制显示小刻度,无论y的范围和图形大小如何(此示例还包括共享的y轴):
如果要创建始终显示任何值范围的小刻度的绘图函数,则需要将
numticks
设置为高值参考文献:answer by ImportanceOfBeingErnest、matplotlib Log Demo、matplotlib Tick Locators
相关问题 更多 >
编程相关推荐