[英]Set the color of the ticker powerlimits using matplotlib
I used the following code to set the power label on the y-axis of my plot to be [1e-3]. 我使用以下代码将图的y轴上的功率标签设置为[1e-3]。 (Meaning that all my y-tick values are multiplied by 1e-3).
(意味着我所有的y-tick值都乘以1e-3)。
ax1 = plt.gca()
y_formatter = mpl.ticker.ScalarFormatter(useOffset=True)
y_formatter.set_powerlimits((-3,5))
ax1.yaxis.set_major_formatter(y_formatter)
In addition I want to color all my ticklabels and axis label blue because I am using a twin axis plot. 另外,由于我正在使用双轴图,因此我想将所有刻度标签和轴标签涂成蓝色。
ax1.set_ylabel('absorpitivity (cm$^{-1}$)',color='b')
for t1 in ax1.get_yticklabels():
t1.set_color('b')
This yields a plot where all my y-tick labels and axis label are blue but the power label at the top of the axis that sets the overall scale is still black. 这将产生一个图,其中所有我的y-tick标签和轴标签都为蓝色,但设置整体比例的轴顶部的功率标签仍为黑色。 How can I also set the power label at the top of the y-axis to be blue also?
如何将y轴顶部的电源标签也设置为蓝色?
I'd really like to post a picture of my plot, but I don't have enough reputation points to post an image. 我真的很想发布自己的地块图片,但我没有足够的声誉点来发布图片。 If this gets up-voted and I get some points I'll edit the post to upload the picture.
如果这被投票赞成,并且我有一些要点,我将编辑帖子以上传图片。
You can access it by using 您可以使用访问它
ax1.yaxis.get_offset_text().set_color('b')
For future reference, and if you haven't tried already, you can find these sort of properties by using the ipython interpreter. 供以后参考,如果您还没有尝试过,可以使用ipython解释器找到这类属性。 Using the tab-completion from the
ax1
instance you can see a list of methods to access. 使用
ax1
实例中的制表符ax1
您可以看到要访问的方法的列表。 From here its some guess work but it might help you in future. 从这里可以进行一些猜测,但将来可能会对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.