0

I used pandas to plot some random time-series data, and I found that it was showing each month as a number followed by a square. Is there any way to fix this?

Here is the code:

>>> import numpy as np
>>> import pandas as pd
>>> import matplotlib.pyplot as plt
>>> ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
>>> ts.plot()
<matplotlib.axes._subplots.AxesSubplot object at 0xb2072b0c>
>>> plt.show()

Here is the plot: random time-series plot

W. Zhu
  • 755
  • 6
  • 16

1 Answers1

0

This can happen if your system locale is set to a non-English one. Given your name I am going to assume you might be using a Chinese locale. So, Pandas or Matplotlib is generating Chinese calendar characters, but the rendering engine you are using cannot display them.

You have at least two options:

  1. Change your system locale, at least when running this code.
  2. Try a different "backend" for Matplotlib. You can get the list of available ones on your system by following this: List of all available matplotlib backends
Community
  • 1
  • 1
John Zwinck
  • 239,568
  • 38
  • 324
  • 436