Thanks to visit codestin.com
Credit goes to github.com

Skip to content

New rcParams requests #5618

Closed
Closed
@notmatthancock

Description

@notmatthancock

Request 1: imshow should have separate rcParams for removing ticks and grid.

The image key should take additional parameters, so that x and y ticks are not present by default, and the grid is not overlaid by default if axes.grid is True. For example image.axis: False would be ideal. To me, it quite reasonable to want axes.grid: True as the default for numerical plots as well a separate default for imshow since they have very different use cases.

Here is an example:

import matplotlib
matplotlib.rcdefaults()
matplotlib.use('qt4agg') # or whatever
matplotlib.rcParams['axes.grid'] = True
matplotlib.rcParams['axes.axisbelow'] = True
matplotlib.rcParams['grid.linestyle'] = '--'
matplotlib.rcParams['grid.color'] = 'red'
matplotlib.rcParams['grid.linewidth'] = 2.0

import matplotlib.pyplot as plt
from numpy import zeros,cos,linspace

x = linspace(0,6.28,100)

fig = plt.figure(figsize=(12,6))

ax1 = fig.add_subplot(121)
ax1.plot(x,cos(x+2*cos(2*x)),lw=3)
ax1.set_title('Ticks and grid are a nice\ndefault for numerical plots.')

ax2 = fig.add_subplot(122)
ax2.imshow(zeros((100,100)), cmap=plt.cm.gray)
ax2.set_title('Ticks and grid are not a nice\ndefault for image plots.')

plt.show()

image-axis

Request 2: Fix inconsistent rcParams behavior with regard to plots that add patches.

Some plots that use patches follow the axes.prop_cycle, while others do not. For example hist obeys both axes.prop_cycle and patch.edgecolor, but ignores patch.facecolor (even if axes.prop_cycle is not set); however, violinplot ignores everything except patch.edgecolor, which is not apparent due to the default alpha setting for violinplot (why is this default??). Here is an example:

import matplotlib
from cycler import cycler

matplotlib.rcdefaults()
matplotlib.use('qt4agg')
matplotlib.rcParams['axes.prop_cycle'] = cycler('color', ['pink','purple','salmon'])
matplotlib.rcParams['patch.facecolor'] = 'pink'
matplotlib.rcParams['patch.edgecolor'] = 'blue'

import matplotlib.pyplot as plt
from numpy.random import randn

fig = plt.figure(figsize=(12,6))

X = randn(100)

ax = fig.add_subplot(121)
for i in range(3):
    ax.hist(X+2*i)

ax = fig.add_subplot(122)
for i in range(3):
    ax.violinplot(X+2*i)

plt.show()

violinplot-color-test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions