Seaborn是一个基于matplotlib的Python可视化库。它的主要目标是提供一个简洁,高级的界面,用于绘制既有信息又有吸引力的统计图形。
I发现了这个情节/图,我想在Python中重新创建它。感觉就像是带有固定标签之类的热图,但我认为应该有一个更好的解决方案。任何帮助或提示
以防止TKINTER在选定帧中绘制/绘制的每个绘制图上打开图形?
#My Imports import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.dates as mdates from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk) from matplotlib.backend_bases import key_press_handler import tkinter as tk import tkinter.ttk as ttk from tkinter import filedialog from datetime import datetime from PIL import ImageTk, Image import seaborn as sns from scipy.stats import linregress #Setting the TKinter window settings window = tk.Tk() screen_width = window.winfo_screenwidth() screen_height = window.winfo_screenheight() window.title("Data Visualizer - Plotting in TKinter") window.geometry(str(int(screen_width*.8))+"x"+str(int(screen_height*.8))) #A function so that selecting the graph doesn't auto plot def nullFunction(*args): print("nullFunction called") #Create test pd.DataFrame #Just something simple to visualize; more columns in actual data df = pd.DataFrame( {"time" : [0,1,2,3,4,5,6,7,8,9], "linear" : [0,1,2,3,4,5,6,7,8,9], "random" : [0,8,4,6,4,7,1,9,2,6], "inverse" : [9,8,7,6,5,4,3,2,1,0]} ) #List the various data columns to be selected later, don't list 'time' #Called on button press after df is created/uploaded def generate_List(): i = 0 listbox.delete('0','end') for column in df.columns: if column == 'time': pass else: listbox.insert(i,column) if (i%2) == 0: listbox.itemconfigure(i, background = '#f0f0f0') i = i+1 plt.ion() #make figure as its own element class FigureCreate: def __init__(self, figsize=(5, 5)): self.fig = plt.figure(figsize=figsize) def get_figure(self): return self.fig #make axes based on listbox selection class AxesCreate: def __init__(self, figure, position=(1, 1, 1)): self.ax = figure.add_subplot(*position) self.figure = figure def get_axes(self): return self.ax def get_fig(self): return self.figure #plot a preselected group of elements; not currently used class CanvasDraw: def __init__(self, axes): self.ax = axes def plot(self, x, y, label=''): self.ax.plot(x, y, label=label) def show(self): self.ax.legend() plt.show() #Called on button press after list is created def plotSet(*args): plt.close #Possibly redundant figure and axis creation methods fig_create = FigureCreate(figsize=(5,5)) fig = fig_create.get_figure() ax_create = AxesCreate(fig, position=(1,1,1)) ax = ax_create.get_axes() #canvas_draw = CanvasDraw(ax) selection = listbox.curselection() for trace in selection: sns.lineplot(data=df, x='time', y=df.columns[trace],ax=ax) #Vlines that will be adjustable after plot issues are solved plt.axvline(df['time'][2],color='green',linestyle='--') plt.axvline(df['time'][4],color='red',linestyle='--') return (ax_create.get_fig()) def plot_MC(fig): # Creating the Tkinter canvas containing the figure #THIS IS WHERE I THINK THE PROBLEM IS, BUT I'M NOT SURE #I thought this would make the canvas in the MC frame, but it seems to want a new plot since plotSet() is returning a figure #Is there a better way to plot specifically in the middle frame, and not force plotSet() to return anything? canvas = FigureCanvasTkAgg(fig, master=frame_MC) canvas.draw() # Placing the canvas on the Tkinter window canvas.get_tk_widget().grid(row=0, column=0) # Creating the Matplotlib toolbar toolbar = NavigationToolbar2Tk(canvas, frame_MC, pack_toolbar=False) toolbar.update() toolbar.grid(row=1, column=0) def are_you_sure(): """ Just a function that opens a message box to confirm window destruction """ if tk.messagebox.askyesno("Quit Dialog","Are you sure you want to quit the app?"): window.destroy() #MC 'Middle-Center' frame_MC = tk.Frame(window) #ML 'Middle-Left' list_frame=tk.Frame(window) listbox=tk.Listbox(list_frame, selectmode='multiple', height=30, width=30) listbox.bind('<<ListboxSelect>>', plotSet) scrollbar=tk.Scrollbar(list_frame, orient="vertical") listbox.config(yscrollcommand=scrollbar.set) scrollbar.config(command = listbox.yview) #TL 'Top-Left' frame_TL = tk.Frame(window) generate_list_button = tk.Button(frame_TL, text="generate list", command=generate_List, width=30) generate_list_button.grid(row=0, column=0, columnspan=3) plot_test_button = tk.Button(frame_TL, text="plot selection", command=plot_MC(plotSet())) plot_test_button.grid(row=1, column=0, columnspan=3) #BL 'Bottom-Left' frame_BL = tk.Frame(window) button_quit = tk.Button(master = frame_BL, text = "Quit", command = are_you_sure, bg = '#FF2222') button_quit.grid(row = 0, column = 0) #Placing elements frame_TL.grid(row=0, column = 0) frame_MC.grid(row = 1, column = 1) frame_BL.grid(row = 2, column = 0) list_frame.grid(row = 1, column = 0) listbox.pack(side = "left", fill = "y") scrollbar.pack(side = "right", fill = "y") #run the gui window.mainloop()
有人可以告诉我为什么此代码中的XZ投影未出现在X-Z平面上? 导入matplotlib.pyplot作为PLT 来自mpl_toolkits.mplot3d导入axes3d 导入numpy作为NP 来自scipy.stats ...
我正在尝试绘制刻面网格,我创建了整个功能,因此更方便,当我在代码编辑器中测试它时,它像在此中一样显示 ,但是当我实际保存时,它会像thi一样显示...
i有一个约400个单元格的jupyter笔记本。总文件大小为8MB,因此我想抑制具有较大尺寸的输出单元,以减少整体文件大小。 有很多
在直方图与海洋绘制的直方图中,当棒重叠时,因为使用色调,颜色会改变,通常是无法区分的。这使得很难向人们解释情节。这变得越来越
如何修复:typeError:relplot()用seaborn
我试图用我的数据框数据绘制带有Seaborn的线路地块 使用: sns.relplot(数据,x =“ invoiceyearmonth”,y =“ price”,hue =“ company”) 给我一个错误: thepeer ...
我可以让它适用于散点图,但是在试图调用线条时,我以某种方式会遇到错误。
使用复选框时,它添加或删除了y_variables列表中的变量并更新绘图。它有效,但我会收到以下错误:
有一种方法可以将散点图覆盖分组的盒子图上的散点图,因此它们不会使用Plotly Graph_Objects来抵消它们?
我正在试图让散点图躺在各自的盒子图上,以充当离群值。由于Plotly的Graph_object.box没有输入预先计算的异常值的方法,因此我一直在尝试这样做。我不希望为项目目的计算离群值。有什么方法可以通过移动散点图来完成此操作,或者也许我忽略了可以做到这一点的功能?