I'm trying to create an app to quickly visualize data from .csv files and easy export to some standard styles for further processing.
I'm trying to visualize data using seaborn as I like how it interacts with dataframes and looks nice. It's embedded in a PyQt5 widget where variables for y and x axis can be selected along with some extra variables.
I can get it to work for the scatterplot but somehow i keep getting errors when trying to call the lineplot.
I tried adding in function to filter data on non numeric values but it has no effect. The only data im calling is a dataframe containing only float values.
def update(self):
self.ax.clear()
#If no y_variables are selected, use x_variable as the y_variable -> otherwise
#will crash
if not self.plot_variables["y_variables"]:
y_variables = [self.plot_variables["x_variable"]]
else:
y_variables = self.plot_variables["y_variables"]
#Melting dataframe for easy plotting with seaborn
long_data = self.dataframe.melt(
id_vars=[self.plot_variables["x_variable"]],
value_vars=y_variables,
var_name='y_variable',
value_name='value'
)
sns.lineplot(
data=long_data,
x=self.plot_variables["x_variable"],
y='value',
hue='y_variable',
ax=self.ax
)
#Update labels and title if available
if self.plot_variables["x_label"]:
self.ax.set_xlabel(self.plot_variables["x_label"])
if self.plot_variables["y_label"]:
self.ax.set_ylabel(self.plot_variables["y_label"])
if self.plot_variables["title"]:
self.ax.set_title(self.plot_variables["title"])
#Add the legend
self.ax.legend()
#Redraw the canvas
self.fig.canvas.draw_idle()
Where x_variable is a string corresponding to a header and y_variables a list of strings corresponding to headers of the dataframe.
When using the checkboxes it adds or removes variables from the y_variables list and updates the plot. It works but I get the following error:
FutureWarning: use_inf_as_na option is deprecated and will be removed in a future version.
Convert inf values to NaN before operating instead.
with pd.option_context('mode.use_inf_as_na', True):
When changing the x_variable in most cases it crashes.
The data is filtered and only contains float Since it works with the scatter plot Im guessing Im using the sns.lineplot wrong?
The program was crashing because it was trying to draw a vertical line for every point in my dataset which is relatively large. By calling the lineplot without the estimator it now works. Solution from other thread: