python - 自定义虚线 matplotlib
问题描述
我正在比较两个图,为了区分它们,我将一个设为实线,另一个设为虚线。但是我可以看到差异,但不清楚。
有没有办法只自定义虚线图,以便我可以清楚地看到差异?我在图中尝试了破折号(5,5),但它也适用于实线。
编辑:这是我的代码的一部分
def plot(self):
# if self.image_count == 2:
# self.image_count = 0
print("plot")
self.counter=0
if self.widget:
self.widget.destroy()
if self.toolbar:
self.toolbar.destroy()
fig = plt.figure()
marker_list = ['-','--','-.',':']
plot1 = fig.add_subplot(111)
#setting x and y label of graph
plot1.set_xlabel('Time (sec)')
# plot1.set_ylabel('Y - axis')
#creating frame for plotting graph
graph_frame = Frame(self.window)
graph_frame.place(relx=0.01, rely=0.1, relwidth=0.98, relheight=0.88)
cs = self.list.curselection()
for index in cs:
f_name = self.list.get(index).split(":")[0]
c_name = self.list.get(index).split(":")[1]
x = self.cev_files[f_name]['Atd[0].Time'].tolist()
y = self.cev_files[f_name][c_name].tolist()
plot1.plot(x, y, linestyle=marker_list[self.counter],linewidth=1, label=c_name)#linewidth=1, markersize=12,
plot1.set_ylabel(c_name)
self.counter +=1
if self.counter==3:
self.counter=0
# handles, labels = plot1.get_legend_handles_labels()
# lgd = plot1.legend(handles, labels, bbox_to_anchor=(0.9, 0.9))
# fig.tight_layout()
# self.image_count +=1
#always place on upper right
plot1.legend(loc="upper right")
# plot1.legend(loc='best')
# plot1.grid(linestyle ='--',linewidth=0.4)
#place on best position
#plot1.legend()
if self.flag==True:
img_name = str(time.time())+'.png'
fig.savefig(img_name, bbox_inches='tight')
self.images.append(img_name)
# creating the Tkinter canvas
# containing the Matplotlib figure
canvas = FigureCanvasTkAgg(fig,
master=graph_frame)
canvas.draw()
PS:我只能使用这种颜色。
解决方案
当您想要在绘图之间有所不同时,线条样式总是更好。您可以使用任何其他样式(不仅仅是虚线)来获得更清晰和不同的情节。对于样式检查here。
根据我的经验,增加 matplotlib 图形的大小将突出显示情节的一些小特征(线条样式等)。你可以尝试增加情节的大小。
from matplotlib.pyplot import figure
figure(figsize=(8, 6), dpi=80)
推荐阅读
- highcharts - 如何在钻取中添加同步图表?
- node.js - 没有进入猫鼬中的保存功能
- amazon-web-services - 在训练数据中反映用户的负面反馈
- node.js - 节点 JS - 无法在 ubuntu 16.04 中安装节点 js 版本 8.9 或更高版本
- linux - SI_TKILL ARM 上的 si_code 用于除零
- python - 尝试将模型从 keras 导出到 CoreML
- c# - 无法加载 DLL 找不到指定的过程。(来自 HRESULT 的异常:0x8007007F)
- c++ - 谷歌测试:接受向量作为参数的动作
- ios - 如何在计算器应用程序中管理计数优先级计算?(迅速)
- javascript - 循环遍历Javascript中的对象列表时如何创建新对象?