【发布时间】:2017-02-10 09:55:06
【问题描述】:
对于大量绘图脚本,我使用 matplotlibs rcParams 为 pandas DataFrames 配置一些标准绘图设置。
这适用于颜色和字体大小,但不适用于here 所述的默认颜色图
这是我目前的方法:
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib import cm
# global plotting options
plt.rcParams.update(plt.rcParamsDefault)
matplotlib.style.use('ggplot')
plt.rcParams['lines.linewidth'] = 2.5
plt.rcParams['axes.facecolor'] = 'silver'
plt.rcParams['xtick.color'] = 'k'
plt.rcParams['ytick.color'] = 'k'
plt.rcParams['text.color'] = 'k'
plt.rcParams['axes.labelcolor'] = 'k'
plt.rcParams.update({'font.size': 10})
plt.rcParams['image.cmap'] = 'Blues' # this doesn't show any effect
# dataframe with random data
df = pd.DataFrame(np.random.rand(10, 3))
# this shows the standard colormap
df.plot(kind='bar')
plt.show()
# this shows the right colormap
df.plot(kind='bar', cmap=cm.get_cmap('Blues'))
plt.show()
只有当我将它作为第二个情节中的参数传递时它才有效:
有什么方法可以永久定义 pandas DataFrame 绘图的标准颜色图吗?
提前致谢!
【问题讨论】:
标签: python pandas matplotlib