简体   繁体   English

Matplotlib:极线等高线图颜色条上的固定边界

[英]Matplotlib: fixed boundaries on a colorbar of a polar contour plot

As it says in the title, I am trying to fix the values of the colorbar (vmin=-3 and vmax=+3) of a polar contour plot.正如标题中所说,我正在尝试修复极地等高线图的颜色条(vmin=-3 和 vmax=+3)的值。 I am going to generate several dozens of such graphs, and the auto scaling of the colorbar makes comparison very difficult.我将生成几十个这样的图形,并且颜色条的自动缩放使比较变得非常困难。

The plot itself is generated by the following code:绘图本身由以下代码生成:

fig, ax = subplots(subplot_kw=dict(projection='polar'))
cax = ax.contourf(thetas, r, values, 130)
cb1 = fig.colorbar(cax)

I have been going through http://matplotlib.sourceforge.org for hours and still haven't found the solution.我已经浏览了http://matplotlib.sourceforge.org几个小时,但仍然没有找到解决方案。 I would point me in the right direction.我会指出我正确的方向。

You can do this by passing in the contour levels yourself.您可以通过自己传入轮廓级别来做到这一点。

Instead of just trying to set vmin=3, vmax=3, pick 130 values between vmin and vmax so they will be the same for all the graphs, independent of the data range.不要仅仅尝试设置 vmin=3、vmax=3,而是在 vmin 和 vmax 之间选择 130 个值,这样它们对于所有图形都是相同的,与数据范围无关。

Try:尝试:

contour_levels = arange(-3, 3, 0.05)

fig, ax = subplots(subplot_kw=dict(projection='polar'))
cax = ax.contourf(thetas, r, values, contour_levels)
cb1 = fig.colorbar(cax)

An alternative solution might be to follow the logic used in this response to a similar question on setting the min and max of a colorbar.另一种解决方案可能是遵循此响应中使用的逻辑来解决有关设置颜色条的最小值和最大值的类似问题。 The main takeaway is the use of set_clim(self, vmin=None, vmax=None) .主要内容是使用set_clim(self, vmin=None, vmax=None) In the context of this question, one of the following might work:在此问题的上下文中,以下方法之一可能有效:

fig, ax = subplots(subplot_kw=dict(projection='polar'))
cax = ax.contourf(thetas, r, values, vmin=-3, vmax=3)
cb1 = fig.colorbar(cax)

OR要么

cb1.set_clim(vmin=-3, vmax=3)

This answer is in the same vein but addresses the requisite of using the same colorbar min/max for multiple graphs.这个答案是相同的,但解决了对多个图形使用相同颜色条最小值/最大值的必要性。

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

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