简体   繁体   English

散点图 plot x 轴刻度标签未显示

[英]Scatter plot x-axis tick labels not showing up

Here is my code:这是我的代码:

import pandas as pd
import matplotlib.pyplot as plt

wine = pd.read_csv('red wine quality.csv')

wine = wine.dropna()

plt.figure()
wine.plot.scatter(x = 'pH', y = 'alcohol', c = 'quality', alpha = 0.4,\
                  cmap = plt.get_cmap('jet'), colorbar = True)
plt.savefig('scatter plot.png')
plt.tight_layout()
plt.show()

Here is the plot that I get:这是我得到的 plot:

在此处输入图像描述

I get a scatter plot with the y-axis labeled as 'alcohol' ranging from 9-15 and the color bar labeled as 'quality' ranging from 3-8.我得到一个散点图 plot,y 轴标记为“酒精”,范围为 9-15,颜色条标记为“质量”,范围为 3-8。 I thought I had designated in my code that the x-axis would show up labeled as 'pH', but I get nothing.我以为我在我的代码中指定了 x 轴将显示为“pH”,但我什么也没得到。 I have tried adjusting my figsize down to [8, 8], setting dpi to 100, and labeling the axes, but nothing will make the x-axis show up.我尝试将我的 figsize 调整为 [8, 8],将 dpi 设置为 100,并标记轴,但没有任何东西可以显示 x 轴。 What am I doing wrong?我究竟做错了什么?

Here is an MCVE to play with:这是一个可以玩的 MCVE:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.DataFrame(np.random.randn(50, 4), columns=['A', 'B', 'C', 'D'])

plt.figure()
df.plot.scatter(x = 'A', y = 'B', c = 'C', alpha = 0.4,\
                  cmap = plt.get_cmap('jet'), colorbar = True)
plt.tight_layout()
plt.show()

X axis label and minor tick labels not showing on Pandas scatter plot is a known and open issue with Pandas (see BUG: Scatterplot x-axis label disappears with colorscale when using matplotlib backend · Issue #36064 ). X axis label and minor tick labels not showing on Pandas scatter plot is a known and open issue with Pandas (see BUG: Scatterplot x-axis label disappears with colorscale when using matplotlib backend · Issue #36064 ).

This bug occurs with Jupyter notebooks displaying Pandas scatterplots that have a colormap while using Matplotlib as the plotting backend.在使用 Matplotlib 作为绘图后端时,显示具有颜色图的 Pandas 散点图的 Jupyter 笔记本会出现此错误。 The simplest workaround is passing sharex=False to pandas.DataFrame.plot.scatter.最简单的解决方法是将sharex=False传递给 pandas.DataFrame.plot.scatter。

See Make pandas plot() show xlabel and xvalues请参阅使 pandas plot() 显示 xlabel 和 xvalues

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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