簡體   English   中英

如何在固定位置(matplotlib)上設置刻度線

[英]How to set ticks on Fixed Position , matplotlib

誰能幫助我使用matplotlib將刻度線設置在固定位置? 我已嘗試使用FixedPosition,如本教程所述:

ax = pl.gca()
ax.xaxis.set_major_locator(eval(locator))

http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html#figures-subplots-axes-and-ticks

但是當我嘗試運行時,它告訴我set_major_locator方法不存在。

一個簡單的例子將非常有用。

謝謝。

只需使用ax.set_xticks(positions)ax.set_yticks(positions)

例如:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.set_xticks([0.15, 0.68, 0.97])
ax.set_yticks([0.2, 0.55, 0.76])
plt.show()

在此處輸入圖片說明

import numpy as np
import matplotlib.ticker as ticker
import matplotlib.pyplot as plt

name_list = ('Omar', 'Serguey', 'Max', 'Zhou', 'Abidin')
value_list = np.random.randint(0, 99, size = len(name_list))
pos_list = np.arange(len(name_list))

ax = plt.axes()
ax.xaxis.set_major_locator(ticker.FixedLocator((pos_list)))
ax.xaxis.set_major_formatter(ticker.FixedFormatter((name_list)))
plt.bar(pos_list, value_list, color = '.75', align = 'center')

plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM