简体   繁体   English

用pcolormesh绘图,改变轴

[英]plotting with pcolormesh, changing axis

Supppose I am plotting a assymetric matrix with pcolormesh: 假设我正在用pcolormesh绘制不对称矩阵:

import prettyplotlib as ppl
import matplotlib.pyplot as plt
import numpy as np

plt.figure()
fig, ax = plt.subplots(1)
ppl.pcolormesh(fig, ax, np.random.randn(10,80))
plt.show()

Now I want to change the x-axis such that its extents are for example -500 to 500 without changing the plot, only the labels of the x-axis, the same for y-axis. 现在,我想更改x轴,以使其范围为-500到500,而无需更改绘图,仅更改x轴的标签,对于y轴相同。 How can I accomplish that? 我该怎么做?

After the ppl.pcolormesh command you can define the ticklables directly using 在ppl.pcolormesh命令之后,您可以使用以下命令直接定义刻度线

ax.set_xticks(xticks)
ax.set_xticklabels(xticklabels)

where xticklabels is an array of your desired labels and xticks are the values at which the labels should apply. 其中xticklabels是所需标签的数组,而xticks是标签应应用的值。

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

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