2

I am just getting to know the Python libraries pandas and matplotlib. Can you show me as an example how to produce a plot similar to this one with matplotlib:

enter image description here

On the y-axis to the right the names of the data instances are listed. The x-axis below is for some value related to each instance.

The data is in .csv format similar to this:

name;value1;value2
uk-2007-05;0.01;1000

Ideally, both value1 and value2 should be plotted in the same plot with different colors or markers.

tacaswell
  • 84,579
  • 22
  • 210
  • 199
clstaudt
  • 21,436
  • 45
  • 156
  • 239

1 Answers1

4
import random
import matplotlib.pyplot as plt

labels = [chr(j) for j in range(97, 115)]

fake_data1 = [random.random() for l in labels]
fake_data2 = [random.random() for l in labels]
y_data = range(len(labels))

figure()
ax = gca()

ax.grid(True)
ax.scatter(fake_data1, y_data, color='r')
ax.scatter(fake_data2, y_data, color='b')

ax.set_yticks(range(len(labels)))
ax.set_yticklabels(labels)
ax.invert_xaxis()
plt.draw()

Where labels is a list of your labels, y_data is indices of the labels for each data point, and fake_data1 and fake_data2 are you x values.

output

tacaswell
  • 84,579
  • 22
  • 210
  • 199