0

I'm using seaborn bib to generate scatter plots. In these scatter plots, three axes on the y-axes should be plotted always, named "Yes", "No" and "Critical".

The code previously generates data for these three outputs Yes, No or Critical. If the previous code generates data for all three, then in the final scatter plot also all three axes are plotted. However - and this is one of the problems - if only for two of the three outputs data is generated, then only these two y-axes were plotted. The one with no data is finally also not plotted in the scatter plot.

I would like to have the scatter plots in an uniform way. All three axes on the y-axes should be plotted, always (even when there is no data available for let's say the "yes"-output), and in the same order ("no" on top, "critical" in the middle, and "yes" on the bottom.)

The problem of the missing uniformity is illustrated in the attached picture, where the axes are transposed. I hope the attached code snippet is enough. If not, please let me know.

enter image description here

plt.figure()
ax = sns.scatterplot(x="Simulation number", y="Here is a text", hue = 'Here is again a text',data=resframe.round(2),  legend=False, palette=dict(Yes="#ff7f0e", No="#1f77b4"))
x_lim = ax.get_xlim()
ax.set_xticks(np.arange(0, x_lim[1], 10))
ax.grid(True, linestyle='--', color='gray', alpha=0.7, which='major', axis='x')
plt.savefig(os.path.join(new_path_p, 'file_title.png'),dpi=300,bbox_inches = 'tight')
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Malouu
  • 1
  • 1
  • `resframe['Here is a text'] = pd.Categorical(resframe['Here is a text'], ['No', 'Yes', 'Critical'], ordered=True)` should ensure all categories are plotted, even if one isn't present in the data. Switch the order of the list to your preferred order. [code and plot](https://i.stack.imgur.com/RNRl6.png) – Trenton McKinney May 30 '23 at 16:02
  • Alternatively, skip using `pd.Categorical`, and set `hue_order=['No', 'Critical', 'Yes']` – Trenton McKinney May 30 '23 at 16:27

0 Answers0