too0ky
November 3, 2020, 11:39am
1
Hey everyone, I am getting these 2 errors. I am using Seaborn to plot my bar graph, and my labels for my x and y-axis are as follow:
g = sns.catplot(data=df_cat, kind=“count”, x=“variable”, hue=“value”, col=“cardio”)
g.set_axis_labels(“variable”, “total”)
However----- I am getting these 2 errors. Everything else seems fine. Can you help?
ERROR: test_bar_plot_number_of_bars (test_module.CatPlotTestCase)
Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-8/test_module.py”, line 26, in test_bar_plot_number_of_bars
actual = len([rect for rect in self.ax.get_children() if isinstance(rect, mpl.patches.Rectangle)])
AttributeError: ‘numpy.ndarray’ object has no attribute ‘get_children’
======================================================================
ERROR: test_line_plot_labels (test_module.CatPlotTestCase)
Traceback (most recent call last):
File “/home/runner/boilerplate-medical-data-visualizer-8/test_module.py”, line 13, in test_line_plot_labels
actual = self.ax.get_xlabel()
AttributeError: ‘numpy.ndarray’ object has no attribute ‘get_xlabel’
Ran 4 tests in 17.636s
FAILED (errors=2)
Your code so far
Click here for my code!
Challenge: Medical Data Visualizer
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
sanity
November 3, 2020, 11:53am
2
sns.catplot doesn’t return figure object, which is expected by the tests. It returns FacetGrid.
too0ky
November 3, 2020, 1:40pm
3
I am a bit confused then, as in the instructions, it says to to draw the catplot using SNS.
“# Draw the catplot with 'sns.catplot()”
Am I suppose to draw the bar plot with Matlibplot?
sanity
November 3, 2020, 1:51pm
4
No, there’s just needed one more step - to take out figure object from the FacetGrid and return that.
too0ky
November 3, 2020, 2:29pm
5
Thank you Sanity! It seems I didn’t understand what some of the earlier posts were saying. For those lost---- : read this:
Apologies for repeatedly asking for help; @sanity
Okay; so the catplot (bar graph) has y-axis read as “count” that label needs to be changed to Total. So; I look up seaborn documentation and it says “methods to tweak presentation”
But; when I use the following code to set_axis labels it doesnt work?
fig.set_axis_labels("", "total")
Traceback (most recent call last):
File “main.py”, line 6, in
medical_data_visualizer.draw_cat_plot()
File “/home/runner/ColossalRegalProject/medical_data_vis…
Courtesy of Sanity:
g = sns.catplot(…)
g.(…) # setting y label in here
fig = g.fig