Skip to content
Advertisement

Python Scatter Plot with Multiple Y values for each X

I am trying to use Python to create a scatter plot that contains two X categories “cat1” “cat2” and each category has multiple Y values. I can get this to work if the number of Y values for each X value is the same by using this following code:

JavaScript

but as soon as the number of Y values for each X value is not the same, I get an error. For example this does not work:

JavaScript

How can I plot different numbers of Y values for each X value and how can I change the X axis from being the numbers 1 and 2 to text categories “cat1” and “cat2”. I would greatly appreciate any help on this!

Here is a sample image of the type of plot I am trying to make:

http://s12.postimg.org/fa417oqt9/pic.png

Advertisement

Answer

How can I plot different numbers of Y values for each X value

Just plot each group separately:

JavaScript

and how can I change the X axis from being the numbers 1 and 2 to text categories “cat1” and “cat2”.

Set ticks and tick labels manually:

JavaScript

Full code:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement