0

I just update my system from Python 2.x to Python 3.x via anaconda distribution. My script that's compatible with Python 2.x is no longer working properly. I've fixed most of it but have no clue how to fix the error regarding matplotlib scatter. I want to plot scatter (circles) points that are color coded with the calculated statistical value. Each circle is labeled accordingly.

Googling around. It suggests that a bug was found in matplotlib (with python 3.x), which scatter does not work with Iterator types of an input arguments. I am not sure if this bug has been fixed with the latest version of matplotlib.

Partial code:

n=[2,4,5,6,7,8,12]
XPOS, YPOS = [0,1,2,3,4,5,6], [0,1,2,3,4,5,6]

data = np.loadtxt(infile)
value = data[:,1]

stat = median_absolute_deviation(value)*1000.

for i in range(7):

    plt.scatter(XPOS[i],YPOS[i], s=1500, c=stat, cmap='RdYlGn_r', edgecolors='black', vmin=0.1, vmax=1.0)
    plt.text(XPOS[i], YPOS[i], n[i])
  File "//anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2841, in scatter
    None else {}), **kwargs)
  File "//anaconda3/lib/python3.7/site-packages/matplotlib/__init__.py", line 1589, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "//anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4446, in scatter
    get_next_color_func=self._get_patches_for_fill.get_next_color)
  File "//anaconda3/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4257, in _parse_scatter_color_args
    n_elem = c_array.shape[0]
IndexError: tuple index out of range
0

1 Answer 1

1

just tried to reproduce this; it seems to work if you pass x, y and c not as scalars but as lists:

import numpy as np
import matplotlib.pyplot as plt

n = [2,4,5,6,7,8,12]
XPOS, YPOS = [0,1,2,3,4,5,6], [0,1,2,3,4,5,6]

N = 8
colors = np.linspace(0, 1, N)

for i in range(N-1):
    plt.scatter([XPOS[i]], [YPOS[i]], s=1500, c=[colors[i]], cmap='RdYlGn_r', 
                edgecolors='black', vmin=0.1, vmax=1.0)
    plt.text(XPOS[i], YPOS[i], n[i])

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you!! It works. Passing list it is with python 3.x.
great! by the way, if you want to go crazy on plotting blobs, check out the networkx package if you don't already know ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.