简体   繁体   中英

matplotlib pyplot not showing axes ticks or labels

When I run the following code:

import matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.show()

In Jupyter notebook lab, I get back an image which only has a diagonal line and is otherwise blank. There are no axis ticks or labels, etc. This is in contrast tothe tutorial which runs the same code and displays an image with axes. Any idea what might be wrong with my setup?

I checked the matplotlib version and it's 2.2.3.

I am running python 2.7.11, and IPython 5.8.0.

It turns out the issue was caused by my Jupyter notebook being set to a dark background. The solution is to add this line of code:

plt.style.use('dark_background')

If the theme of a Jupyter notebook is set to dark mode, this issue happens usually. the fix for this problem is to define the style by: plt.style.use(style_name) .

Where style_name can either be "fivethirtyeight", "classic", "dark_background", or "seaborn-white", etc. An extensive list of available themes is seen with the code sorted(plt.style.available) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM