Maybe something like this:
import matplotlib.pyplot
import pylab
x = [1,2,3,4]
y = [3,4,8,6]
matplotlib.pyplot.scatter[x,y]
matplotlib.pyplot.show[]
EDIT:
Let me see if I understand you correctly now:
You have:
test1 | test2 | test3
test3 | 1 | 0 | 1
test4 | 0 | 1 | 0
test5 | 1 | 1 | 0
Now you want to represent the above values in in a scatter plot, such that value of 1 is represented by a dot.
Let's say you results are stored in a 2-D list:
results = [[1, 0, 1], [0, 1, 0], [1, 1, 0]]
We want to transform them into two variables so we are able to plot them.
And I believe this code will give you what you are looking for:
import matplotlib
import pylab
results = [[1, 0, 1], [0, 1, 0], [1, 1, 0]]
x = []
y = []
for ind_1, sublist in enumerate[results]:
for ind_2, ele in enumerate[sublist]:
if ele == 1:
x.append[ind_1]
y.append[ind_2]
matplotlib.pyplot.scatter[x,y]
matplotlib.pyplot.show[]
Notice that I
do need to import pylab
, and you would have play around with the axis labels. Also this feels like a work around, and there might be [probably is] a direct method to do this.
Scatter plots of [x,y] point pairs are created with Matplotlib's The required positional arguments supplied to The general syntax of the The next code section shows how to build a scatter plot with Matplotlib. First, 150 random [but semi-focused] x and y-values are created using NumPy's In [1]:Scatter Plots
ax.scatter[]
method. ax.scatter[]
are two lists or arrays. The first positional argument
specifies the x-value of each point on the scatter plot. The second positional argument specifies the y-value of each point on the scatter plot.ax.scatter[]
method is shown below.ax.scatter[x-points, y-points]
np.random.randn[]
function. The x and y-values are plotted on a scatter plot using Matplotlib's ax.scatter[]
method. Note the number
of x-values is the same as the number of y-values. The size of the two lists or two arrays passed to ax.scatter[]
must be equal.
import numpy as np import matplotlib.pyplot as plt # if uising a Jupyter notebook, include: %matplotlib inlineMatplotlib scatter plots can be customized by supplying additional keyword arguments to the# random but semi-focused data x1 = 1.5 np.random.randn[150] + 10 y1 = 1.5 np.random.randn[150] + 10 x2 = 1.5 np.random.randn[150] + 4 y2 = 1.5 np.random.randn[150] + 4 x = np.append[x1,x2] y = np.append[y1,y2]
fig, ax = plt.subplots[] ax.scatter[x,y]
plt.show[]
ax.scatter[]
method. Note the keyword arguments used in ax.scatter[]
are a little different from the keyword arguments used in other Matplotlib plot types.
marker size | s=
| ax.scatter[x, y, s=10]
|
marker color | c=
| ax.scatter[x, y, c=[122, 80, 4]]
|
marker opacity | alpha=
| ax.scatter[x, y, alpha=0.2]
|
Each of these keyword arguments can be assigned an individual value which applies to the whole scatter plot. The ax.scatter[]
keyword arguments can also be assigned to lists or arrays. Supplying a list or array controls the properties of each marker in the scatter plot.
The code section below creates a scatter plot with randomly selected colors and areas.
In [2]:
import numpy as np import matplotlib.pyplot as plt # if uising a Jupyter notebook, include: %matplotlib inlinex1 = 1.5 np.random.randn[150] + 10 y1 = 1.5 np.random.randn[150] + 10 x2 = 1.5 np.random.randn[150] + 4 y2 = 1.5 np.random.randn[150] + 4 x = np.append[x1,x2] y = np.append[y1,y2] colors = np.random.rand[1502] area = np.pi [8 np.random.rand[1502]]**2
fig, ax = plt.subplots[]
ax.scatter[x, y, s=area, c=colors, alpha=0.6] ax.set_title['Scatter plot of x-y pairs semi-focused in two regions'] ax.set_xlabel['x value'] ax.set_ylabel['y value']
plt.show[]