import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
from matplotlib.ticker import MultipleLocator
import seaborn as sns
import pandas as pd
#CSAMT
fig, ax = plt.subplots(figsize = (28,10))
scat = pd.read_csv('C:/Users/18613/Desktop/synthetic.csv',skiprows=1,index_col=0,nrows=50)
h=sns.heatmap(scat, annot=False,vmin=10, vmax=90,cbar=False,linecolor="black",cmap='jet')#不要线
plt.xticks(rotation=360)
plt.yticks(rotation=360)
ax.xaxis.set_major_locator(ticker.MultipleLocator(101/10))
ax.set_xlabel('Station/m', fontsize = 30)#坐标不合适60 260 460 ... 1860
ax.yaxis.set_major_locator(ticker.MultipleLocator(50/10))
ax.set_ylabel('log(f)/Hz', fontsize = 30)#坐标不合适,应该是频率而不是频率数
ax.tick_params(which='both',width=4,length=8,colors='black')
ax.tick_params(direction='out')
plt.tick_params(labelsize=25)
cb=h.figure.colorbar(h.collections[0]) #显示colorbar
cb.ax.tick_params(labelsize=25)
plt.show()
为什么我画出来的图是这样的?x轴y轴上都没有坐标?去掉ax.xaxis.set_major_locator反而就能显示出来了,但是很密?有大神知道怎么修改吗?
解决了,matplotlib版本号的问题,3.1.2版本无法显示,升级到3.2.2版本就可以显示了
按道理,图应该像这样有坐标轴,且按一定间隔显示才对啊?
Python热力图作图坐标轴无法显示数字的问题可能出现在使用的绘图库或者绘图函数上。请问您是在使用哪个库或函数来绘制热力图呢?