How to use 'pandas plot multiple columns' in Python

Every line of 'pandas plot multiple columns' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
134def draw_plots(self, column_x, column_y, column_hue):
135 """
136 Function that draws plot in the panel.
137
138 Args:
139 column_x --> 1D dataframe: dataframe column extracted from df
140 (i.e. column_x = df[column_x_name]) as x axis data
141 column_y --> 1D dataframe: dataframe column extracted from df
142 (i.e. column_y = df[column_y_name]) as y axis data
143 column_hue --> 1D dataframe: dataframe column extracted from df
144 (i.e. column_hue = df[column_hue_name]) as legend data
145
146 Returns: None
147 """
148
149 # Reset plot first
150 self.box_axes.clear()
151 self.violin_axes.clear()
152
153 # Box plot
154 try:
155 sns.boxplot(x=column_x, y=column_y, hue=column_hue, data=self.df, ax=self.box_axes)
156 except ValueError as e:
157 # log Error
158 _log_message = "\nBox plot failed due to error:\n--> {}".format(e)
159 pub.sendMessage("LOG_MESSAGE", log_message=_log_message)
160
161 # Violin plot
162 try:
163 sns.violinplot(x=column_x, y=column_y, hue=column_hue, data=self.df, split=True, ax=self.violin_axes)
164 except ValueError as e:
165 # log Error
166 _log_message = "\nVolin plot failed due to error:\n--> {}".format(e)
167 pub.sendMessage("LOG_MESSAGE", log_message=_log_message)
168
169 # Set plot style
170 self.box_axes.set_title("Box Plot for {} and {}".format(column_x, column_y))
171 self.box_axes.set_ylabel(column_y)
172 self.box_axes.set_xlabel(column_x)
173 self.box_canvas.draw()
174
175 self.violin_axes.set_title("Violin Plot for {} and {}".format(column_x, column_y))
176 self.violin_axes.set_ylabel(column_y)
177 self.violin_axes.set_xlabel(column_x)
178 self.violin_canvas.draw()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

21def plot(ax, x, y, **kwargs):
22 '''
23
24 '''
25
26 # Determine the label text
27 label = kwargs.pop('label', None)
28 if label is None:
29 label = '%s (%s)' % (y.name, y.parent)
30
31 # Determine the color
32 color = kwargs.pop('color', None)
33 if color is None:
34 color = y.color
35
36 # Axis labels
37 if len(x.unit):
38 ax.set_xlabel('%s (%s)' % (x.description, x.unit))
39 else:
40 ax.set_xlabel(x.description)
41 if len(y.unit):
42 ax.set_ylabel('%s (%s)' % (y.description, y.unit))
43 else:
44 ax.set_ylabel(y.description)
45
46 # Plot
47 l = ax.plot(x, y, color = color, label = label, **kwargs)
48
49 return l

Related snippets