Jim Crigler
Jim Crigler

Reputation: 1

matplotlib plot not showing empty vals at ends

I need to show the empty slots at the ends of the plot. Code to show what I mean:

a = pd.DataFrame([ 1,5,3,2,7 ], index=['b','e','g','h','d'])
i = pd.DataFrame(index=['a','b','c','d','e','f','g','h','i','j','k','l'])
c = pd.concat([i, a], axis=1)
plt.plot(c, lw=0, marker='o')
plt.show()

The content of c is

     0
a  NaN
b  1.0
c  NaN
d  7.0
e  5.0
f  NaN
g  3.0
h  2.0
i  NaN
j  NaN
k  NaN
l  NaN

This shows a chart (can't upload, not enough points, sorry) that has X axis labels b, c, d, e, f, g, h; c and f have no associated points, just as I want.

I have tried plt.xticks, ax.set_xlabels

How can I get the labels for a, i, j, k, l to show?

Upvotes: 0

Views: 33

Answers (1)

davidli
davidli

Reputation: 371

import pandas as pd
import matplotlib.pyplot as plt

a = pd.DataFrame([ 1,5,3,2,7 ], index=['b','e','g','h','d'])
i = pd.DataFrame(index=['a','b','c','d','e','f','g','h','i','j','k','l'])
c = pd.concat([i, a], axis=1)
fig, ax = plt.subplots()
ax.plot(c.index, c, lw=0, marker='o')
ax.set_xticks(c.index)
plt.show()

Upvotes: 2

Related Questions