In scientific research plotting, it’s always bar charts instead of line charts.
Possible reasons:
The visual footprint of point lines is relatively small compared to bar
Line charts are aggregated together when there is a meaningful comparison of data along the y-axis.
global setting
font things, Attention, global settings have higher priority to get work
1 2 3 4 5 6 7
matplotlib.rcParams.update({ "pgf.texsystem": "pdflatex", 'font.family': 'serif', # 'text.usetex': True, # comment to support bold font in legend, and font will be bolder # 'pgf.rcfonts': False, })
# plotly fig.update_layout(height=350, width=50 * graph_data.size(), margin=dict(b=10, t=10, l=20, r=5), bargap=0.2# x tick distance, 1 is the normalize-distance of adjacent bars )
relative position
1 2
# mpl: Adjust the left margin to make room for the legend, left & right chart vertical line position from [0,1] plt.subplots_adjust(left=0.1, right=0.8)
set x axis
1 2 3 4 5 6 7 8 9 10 11 12
# mpl: x = np.arange(len(graph_data.x)) # the label locations, [0, 1, 2, 3, 4, 5, 6, 7] # set the bar move to arg1 with name arg2 ax.set_xticks(x + (group_count-1)*0.5*width, graph_data.x) plt.xticks(fontsize=graph_data.fontsize+4) # Adjust x-axis limits to narrow the gap plt.xlim(-(0.5+gap_count)*width, x_count - 1 + (group_count-1)*width + (0.5+gap_count)*width)
# mpl ax.set_ylabel(yaxis_title, fontsize=graph_data.fontsize, fontweight='bold') plt.grid(True, which='major',axis='y', zorder=-1.0) # line and bar seems need to set zorder=10 to cover it plt.yticks(np.arange(0, max_y ,10), fontsize=graph_data.fontsize) # step 10 plt.yscale('log',base=10) # or plt.yscale('linear') ax.set_ylim(0.1, max_y) ## highlight selected y-label: https://stackoverflow.com/questions/73597796/make-one-y-axis-label-bold-in-matplotlib
# plotly fig.update_layout( yaxis_range=[0,maxY], yaxis=dict( rangemode='tozero', # Set the y-axis rangemode to 'tozero' dtick=maxY/10, gridcolor='rgb(196, 196, 196)', # grey gridwidth=1, ), )
Bolden Contour Lines
Entire Figure
1 2 3 4 5 6 7 8
# mpl ?
# plotly: Add a rectangle shape to cover the entire subplot area fig.add_shape(type="rect", xref="paper", yref="paper", x0=0, y0=0, x1=1, y1=1, line=dict(color="black", width=0.7))
and Each Bar Within
1 2 3 4
# mpl: Create a bar chart with bold outlines plt.bar(categories, values, edgecolor='black', linewidth=2)
# plotly: ?
legend box
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# mpl: ax.legend(loc='upper left', ncols=3, fontsize=graph_data.fontsize) # legend out-of-figure, (1.02, 1) means anchor is upper right corner plt.legend(loc='upper left', bbox_to_anchor=(1.02, 1), borderaxespad=0)
# Calculate the legend width based on the figure width fig_size = plt.gcf().get_size_inches() fig_width = fig_size[0] # Move the legend to the center above the ceiling line plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.1), ncol=2, # ncol=2 to have labels in one line frameon=False, # frameon=False removes the legend box outline columnspacing=fig_width, # distance between each label handlelength=1.0, # label-box width (unit is text fontsize) handleheight=1.0, # label-box heigh (unit is text fontsize) prop={'size': 20, 'weight': 'bold'} # text fontsize )
# mpl: white hugo hatch with black bar edge. # Problem: because the bug of mpl. hatch color follow the edge color # Solved: draw bar twice, first the white hugo hatch with white bar edge. Second empty figure with black bar edge. # white doubel ref: https://stackoverflow.com/questions/38168948/how-to-decouple-hatch-and-edge-color-in-matplotlib # ref2: https://stackoverflow.com/questions/71424924/how-to-change-the-edge-color-of-markers-patches-in-matplotlib-legend color_palette = ['black', (193/255, 1/255, 1/255), 'w', (127/255, 126/255, 127/255), 'blue'] pattern_list = ["", "/", "+", "\\", "x"] edgecolor_list = ['w', 'w', (0/255, 176/255, 80/255), 'w', 'w'] ax.bar(x + offset, measurement, width, label=species_name, color=color_palette[idx], hatch = pattern_list[idx], edgecolor=edgecolor_list[idx], linewidth=1, ) ax.bar(x + offset, measurement, width, label=species_name, color = "none", edgecolor='black', linewidth=1, ) # related legend: https://stackoverflow.com/questions/71424924/how-to-change-the-edge-color-of-markers-patches-in-matplotlib-legend handles1, labels1 = ax.get_legend_handles_labels() plt.legend([handles1[2*idx]+handles1[2*idx+1] for idx inrange(group_count)], [labels1[2*idx] for idx inrange(group_count)], loc='upper center', bbox_to_anchor=(0.5, 1.12), ncol=group_count, # have labels in one line frameon=False, # bbox_transform=plt.gcf().transFigure, columnspacing=legend_width, # handlelength=1.0, handleheight=1.2, prop={'size': graph_data.fontsize, 'weight': 'heavy'} )
# plotly: find the overflow overflow_pattern = ["/"if y > maxY else""for y in entry[1]] fig.add_bar(x=x,y=yList, name=barName, marker=dict( color=color_list[i], pattern_shape = overflow_pattern, line=dict(color='black', width=2) ), textfont=dict(size=graph_data.fontsize), ) # legend legend_num = len( barDict.items()) fig.update_layout(barmode="relative",
# legend_title="Legend Title", legend = dict( entrywidthmode='fraction', # https://plotly.com/python/legend/ entrywidth= 0.2, x=0.5 - 0.5 * legend_num * 0.2, # Set x to 0.5 for the center y=1.2, # Set y to a value greater than 1 to move it above the plot orientation="h", # Display legend items in a single line ), )
Out-box text
To draw symmetry chart, we need to special highlight the overflow bar number.
If the ancher point locate in the plot box, it’s easy to show text above the ceil line using textposition="bottom" like option. In the opposite scenario, plotly and mathplotlib all will hide the out-box text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# plotly fig.add_annotation( x=[x[0][i],x[1][i]], # 注释的 x 坐标为 "bc" y=min(maxY,entry), # 注释的 y 坐标为该列的最大值 text=f"{entry:.2f}", # 注释的文本内容 # valign = "bottom", # text position in text box(default invisible) yanchor = "bottom", # text box position relative to anchor showarrow=False, # 显示箭头 # bgcolor="rgba(255, 255, 255, 0.8)", # 注释框背景颜色 font=dict(size=graph_data.fontsize+2) # 注释文本字体大小 )
# mathplotlib # Create labels for overflowed values for i, value in enumerate(values): if value > maxY: ax.annotate(f'Overflow: {value:.2f}', (i, maxY), ha='center', va='bottom', fontsize=12)
But mlb can write text out box.
1 2 3 4 5
ax.text(1, -1.6, 'Increasing', ha="center")
# first parameter is text, xy is the anchor point, xytext is the text, # xytext 2 xy is a relative distance ax.annotate('yahaha', xy=(0, -0.1), xycoords='axes fraction', xytext=(1, -0.1))
out-box line
mathplotlib(mpl) can achieve this using ref, but there are few blogs about plotly.
1 2 3 4 5 6 7 8 9 10
# mpl: from 1*1 size full-graph (0.5,0.2) to point (1,0.8) # transform=gcf().transFigure : gcf() stands for "get current figure," and .transFigure indicates that the coordinates provided in [0.5, 0.5], [0, 1] are in figure-relative coordinates. This means that the line's position is defined relative to the entire figure, not just the axes # clip_on=False : This setting means that the line is not clipped at the edges of the axes. It allows the line to extend beyond the axes' boundaries. from pylab import * plot([0.5, 1], [0.2, 0.8], color='lightgreen', linestyle='--', lw=1 ,transform=gcf().transFigure, clip_on=False)
# mpl: arrow from xy 2 xytext # xycoords='figure fraction' to Add annotation to the figure (full graph) ax.annotate('', xy=(0, -0.1), xycoords='axes fraction', xytext=(1, -0.1),\ arrowprops=dict(arrowstyle="->", color='violet'))
in-box line
1 2 3 4 5 6 7
# mpl: ax.axhline(y=12, color='red', linestyle='--', label='Horizontal Line at y=12') ax.axvline(x=3, color='green', linestyle='-.', label='Vertical Line at x=3')
C or C++ language standard. eg ‘c++11’ == ‘c++0x’ ‘c++17’ == ‘c++1z’, which ‘c++0x’,’c++17’ is develop codename
-Wunknown-pragmas
未知的pragma会报错(-Wno-unknown-pragmas 应该是相反的)
-fomit-frame-pointer
不生成栈帧指针,属于-O1优化
-Wstack-protector
没有防止堆栈崩溃的函数时warning (-fno-stack-protector)
-MMD
only user header files, not system header files.
-fexceptions
Enable exception handling.
-funwind-tables
Unwind tables contain debug frame information which is also necessary for the handling of such exceptions
-fasynchronous-unwind-tables
Generate unwind table in DWARF format. so it can be used for stack unwinding from asynchronous events
-fabi-version=n
Use version n of the C++ ABI. The default is version 0.(Version 2 is the version of the C++ ABI that first appeared in G++ 3.4, and was the default through G++ 4.9.) ABI: an application binary interface (ABI) is an interface between two binary program modules. Often, one of these modules is a library or operating system facility, and the other is a program that is being run by a user.
-fno-rtti
Disable generation of information about every class with virtual functions for use by the C++ run-time type identification features (dynamic_cast and typeid). If you don’t use those parts of the language, you can save some space by using this flag
-faligned-new
Enable support for C++17 new of types that require more alignment than void* ::operator new(std::size_t) provides. A numeric argument such as -faligned-new=32 can be used to specify how much alignment (in bytes) is provided by that function, but few users will need to override the default of alignof(std::max_align_t). This flag is enabled by default for -std=c++17.
-Wl, xxx
pass xxx option to linker, e.g., -Wl,-R/staff/shaojiemike/github/MultiPIM_icarus0/common/libconfig/lib specify a runtime library search path for dynamic libraries (shared libraries) during the linking process.
General Optimization Options
-O, -O2, -O3
-O3 turns on all optimizations specified by -O2
and also turns on the -finline-functions, -funswitch-loops, -fpredictive-commoning, -fgcse-after-reload, -ftree-loop-vectorize, -ftree-loop-distribute-patterns, -ftree-slp-vectorize, -fvect-cost-model, -ftree-partial-pre and -fipa-cp-clone options
Unroll loops whose number of iterations can be determined at compile time or upon entry to the loop. -funroll-loops implies -frerun-cse-after-loop. This option makes code larger, and may or may not make it run faster.
-funroll-all-loops
Unroll all loops, even if their number of iterations is uncertain when the loop is entered. This usually makes programs run more slowly.-funroll-all-loops implies the same options as -funroll-loops,
max-unrolled-insns
The maximum number of instructions that a loop should have if that loop is unrolled, and if the loop is unrolled, it determines how many times the loop code is unrolled. 如果循环被展开,则循环应具有的最大指令数,如果循环被展开,则它确定循环代码被展开的次数。
max-average-unrolled-insns
The maximum number of instructions biased by probabilities of their execution that a loop should have if that loop is unrolled, and if the loop is unrolled, it determines how many times the loop code is unrolled. 如果一个循环被展开,则根据其执行概率偏置的最大指令数,如果该循环被展开,则确定循环代码被展开的次数。
max-unroll-times
The maximum number of unrollings of a single loop. 单个循环的最大展开次数。
R_X86_64_PC32。重定位一个使用 32 位 PC 相对地址的引用。回想一下 3.6.3 节,一个 PC 相对地址就是距程序计数器(PC)的当前运行时值的偏移量。当 CPU 执行一条使用 PC 相对寻址的指令时,它就将在指令中编码的 32 位值加上 PC 的当前运行时值,得到有效地址(如 call 指令的目标),PC 值通常是下一条指令在内存中的地址。(将 PC 压入栈中来使用)
typedefstruct { long offset; /* Offset of the reference to relocate */ long type:32, /* Relocation type */ symbol:32; /* Symbol table index */ long addend; /* Constant part of relocation expression */ } Elf64_Rela;
目标文件与库的位置
链接器通常从左到右解析依赖项,这意味着如果库 A 依赖于库 B,那么库 B 应该在库 A 之前被链接。
objdump -g <archive_file>.a # 如果.o文件有debugging symbols,会输出各section详细信息 Contents of the .debug_aranges section (loaded from predict-c.o): # 没有则如下 cabac-a.o: file format elf64-x86-64