python-3.x - pyplot 从 2.1.1 到 2.2.2 的不同行为
问题描述
我已经完成了一个 python 脚本来准备我的情节。我使用 debian 来准备这个,其中 matplot lib 的版本是 2.1.1 ,而现在我正在转向 Archlinux,我在其中处理版本 2.2.2 ,问题是在 2.1.1 中我以这种方式定义所有参数(例如循环器颜色):
plt.rc_context({ 'axes.prop_cycle': cycler('color', ['#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3', '#66C2A5', '#FC8D62'] )})
在 2.2.2 我找到了这个解决方案:
plt.rc('axes', prop_cycle=(cycler('color', ['#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3', '#66C2A5', '#FC8D62'])))
问题是我已经定义了所有这些参数:
plt.rc_context({'axes.edgecolor': self.parameter['box'] }) # BOX colors
plt.rc_context({'axes.linewidth':'1.2' }) # BOX width
plt.rc_context({'axes.xmargin':'0' })
plt.rc_context({'axes.ymargin':'0' })
plt.rc_context({'axes.labelcolor':self.parameter['axeslabel']})
plt.rc_context({'axes.axisbelow':'True' })
plt.rc_context({'xtick.color': self.parameter['xtickcolor']}) # doesn't affect the text
plt.rc_context({'ytick.color': self.parameter['ytickcolor']}) # doesn't affect the text
#plt.rc_context({ 'axes.prop_cycle': self.colors('tthmod')})
plt.rc_context({ 'axes.prop_cycle': cycler('color', ['#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3', '#66C2A5', '#FC8D62'] )})
plt.rc_context({ 'grid.linestyle': '--'})
plt.rc_context({ 'grid.alpha': '1'})
#plt.rc_context({ 'grid.color': '#E5E5E5'})
plt.rc_context({ 'grid.color': '#FFFFFF'})
我在哪里可以找到解决方案??我的意思是让我们以“我的方式”工作或如何更改语法以获得相同的结果!谢谢
编辑 si ma perche` non mi prende quelle versioni che avevo scritto (cosa che faceva la versione 2.1.1) mi lascia pensare che qualcosa sia cambiato!!
解决方案
一次指定多个 rc 参数的一种可能方法是使用字典并matplotlib.rcParams
用它更新。
import matplotlib.pyplot as plt
from cycler import cycler
myparams = {'axes.edgecolor': "red", # BOX colors
'axes.linewidth': 1.2, # BOX width
'axes.xmargin': 0,
'axes.ymargin': 0,
'axes.labelcolor': "crimson",
'axes.axisbelow': True,
'xtick.color': "blue", # doesn't affect the text
'ytick.color': "gold", # doesn't affect the text
'axes.prop_cycle': cycler('color', ['#8DA0CB', '#E78AC3', '#A6D854', '#FFD92F', '#E5C494', '#B3B3B3', '#66C2A5', '#FC8D62']),
'grid.linestyle': '--',
'grid.alpha': '1',
'grid.color': '#E5E5E5'}
plt.rcParams.update(myparams)
相反,如果您想使用上下文,则可以这样做
with plt.rc_context(myparams):
plt.plot([1,2,3])
无论如何,在上下文之外使用plt.rc_context
(如问题)可能没有太大意义。
推荐阅读
- sql-server - 运行数据库脚本错误 SQL Server/报表服务器
- twitter-bootstrap - 在 div 以外的其他元素中使用 row 或 col 是否被认为是一种不好的做法?
- google-bigquery - 使用 BigQuery 进行一次热编码(虚拟变量)
- java - 为什么 uri 变量不为 null 时 HttpUriRequest.getURI() 返回 null?
- python - 如何将数据框中每对行的第一行和第二行添加到单独的列表中?
- python - 什么更快?将文件行加载到列表中或在for循环中逐行处理文件对象?Python
- html - 如何使用 HTML / Bootstrap 在图像网格中提供空格
- javascript - 最小化导入大小 (js)
- php - 尝试在安装 voyager 后运行 php artisan migrate:fresh 它给了我这个错误
- ruby-on-rails - Rails ActiveRecord::PendingMigrationError 上的迁移错误 ruby