A. python matplotlib設置y軸次標簽怎麼設置
[python] view plain
#!/usr/bin/env python
#-*- coding: utf-8 -*-
#---------------------------------------------------
#演示MatPlotLib中設置坐標軸主刻度標簽和次刻度標簽.
#對於次刻度顯示,如果要使用默認設置只要matplotlib.pyplot.minorticks_on()
#---------------------------------------------------
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
#---------------------------------------------------
xmajorLocator = MultipleLocator(20) #將x主刻度標簽設置為20的倍數
xmajorFormatter = FormatStrFormatter('%5.1f') #設置x軸標簽文本的格式
xminorLocator = MultipleLocator(5) #將x軸次刻度標簽設置為5的倍數
ymajorLocator = MultipleLocator(0.5) #將y軸主刻度標簽設置為0.5的倍數
ymajorFormatter = FormatStrFormatter('%1.1f') #設置y軸標簽文本的格式
yminorLocator = MultipleLocator(0.1) #將此y軸次刻度標簽設置為0.1的倍數
t = arange(0.0, 100.0, 1)
s = sin(0.1*pi*t)*exp(-t*0.01)
ax = subplot(111) #注意:一般都在ax中設置,不再plot中設置
plot(t,s,'--r*')
#設置主刻度標簽的位置,標簽文本的格式
ax.xaxis.set_major_locator(xmajorLocator)
ax.xaxis.set_major_formatter(xmajorFormatter)
ax.yaxis.set_major_locator(ymajorLocator)
ax.yaxis.set_major_formatter(ymajorFormatter)
#顯示次刻度標簽的位置,沒有標簽文本
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_minor_locator(yminorLocator)
ax.xaxis.grid(True, which='major') #x坐標軸的網格使用主刻度
ax.yaxis.grid(True, which='minor') #y坐標軸的網格使用次刻度
show()
##########################################################
B. python matlibplot 畫圖控制對數坐標刻度顯示
你試試下面這句指令,主要是subsy控制的,你的那個指令是控制x軸的,並且不太好使。我試了下面這個還挺好使的。
ax.set_yscale('log',nonposy='mask',subsy=[0])
C. python matplotlib怎麼讓x軸只顯示固定個數的標簽
1、首先點擊鍵盤 win+r,打開運行窗口;在窗口中輸入「cmd",點擊確定,打開windows命令行窗口。
D. python的matplotlib的pyplot模塊,plt.yticks()設置刻度不能超過用來做圖的數據值了
python的matplotlib的pyplot模塊,plt.yticks()設置刻度不能超過用來做圖的數據值了。比較專業,要不然你可以問下老師或者專業人士。
E. python matplotlib的坐標軸怎麼設置范圍
plt.ylim(24.9,25.2)
F. python中怎麼讓圖所有坐標軸都有刻度
plt.tick_params(top='on', right='on', which='both') # 顯示上側和右側的刻度
plt.rcParams['xtick.direction'] = 'in' #將x軸的刻度線方向設置向內
plt.rcParams['ytick.direction'] = 'in' #將y軸的刻度方向設置向內
(PS:如果第一次運行上面的兩個命令坐標軸沒有朝內的話,關閉圖像,再運行一次就可以達到效果了。)
G. 請教如何自定義python的matplotlib中的X軸刻度的問題
初學matplotlib,請大家多多包涵
小弟的目的是,早3點到晚10點之間,每30秒監控一次主機的CPU、內存使用率等指標,並繪製成折線圖。
圖的橫坐標為時間(時分秒),縱坐標為監控指標
以CPU監控為例,目前小弟的做法是,生成兩個list,一個存datetime.datetime格式的時間(年月日時分秒),另外一個list存我的監控結果。
然而,作圖的時候,默認的圖形橫坐標時間間隔太短,畫出的線太密,效果可如下圖:
小弟希望將橫坐標的監控作為30分鍾一格,同時每個大刻度之間增加子刻度(3分鍾一格)請問如何能夠實現呢?非常感謝大家!小弟希望將橫坐標的監控作為30分鍾一格,同時每個大刻度之間增加子刻度(3分鍾一格)請問如何能夠實現呢?非常感謝大家!
matplotlib提供基本的介面:
from matplotlib.dates import AutoDateLocator, DateFormatter autodates = AutoDateLocator() yearsFmt = DateFormatter('%Y-%m-%d %H:%M:%S') figure.autofmt_xdate() #設置x軸時間外觀 ax.xaxis.set_major_locator(autodates) #設置時間間隔 ax.xaxis.set_major_formatter(yearsFmt) #設置時間顯示格式 ax.set_xticks() #設置x軸間隔 ax.set_xlim() #設置x軸范圍
H. Python的問題:請問如何設置坐標軸上的刻度間距
看你用什麼庫了,有的庫不支持指定軸極值與步長,只能讓它自己適應,那就沒辦法。
I. python使用matplotlib畫圖怎麼讓坐標軸刻度成為底數乘以10的n次方的形式
importmatplotlib.pyplotasplt
frommatplotlib.font_managerimportFontProperties
importrandom
importnumpyasnp
xlist=[]
ylist=[]
a=[[np.random.randint(1,100)forjinrange(1,3)]foriinrange(1,101)]
print(a)
forx,yina:
xlist.append(x)
ylist.append(y)
plt.scatter(xlist,ylist)
font=FontProperties(fname=r"c:windowsfontssimsun.ttc",size=15)
plt.xlabel('10^n',fontproperties=font)
plt.ylabel('y軸',fontproperties=font)
plt.show()