Issue 1:
Bug summary

Pixel widths appear irregularly in pcolor(x, y, z, rasterized=True), while x and y are regular. Using rasterized=False provides correct (equal size) pixels, but saving the figure to .png (instead of .pdf) will show the same irregular pixel width bug.

It looks like a resampling bug, which messes up precise data visualization completely.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
x, y = np.meshgrid(range(500), range(2))
z = [np.tile([0,1],250), np.tile([0,1],250)]
fig, ax = plt.subplots(1,1, figsize=(10,2))
im = ax.pcolor(x, y, z, rasterized=True)
ax.set_xticks(np.arange(0,40))
fig.savefig('test.pdf')
plt.show()

Actual outcome

In the resulting plot, some pixels are thinner, and some are thicker, than they should be.

rasterize=True (zoom-in to the lower left corner)

Expected outcome

rasterize=False (zoom-in to the lower left corner)

Additional information

This behaviour depends on the number of pixels plotted, for me it becomes visible above len(x)>100.

The spread between thicker and thinner lines increases with increasing size of the input array.

If the view is reduced to a lower number of pixels (e.g., ax.set_xlim(0,10)), the effect is no longer visible.

Operating system

Windows

Matplotlib Version

3.5.1

Matplotlib Backend

inline

Python version

3.9.6

Jupyter version

No response

Installation

pip

Issue 2:
Matplotlib version 1.5.1

Python 3.4.4 on Windows via Anaconda 2.2.0 (64-bit)

Also occured on a Python 3.5.1 install on Lubuntu via Anaconda 4.0

Jupyter QtConsole 4.1.0; IPython verion 4.0.0

I made some functions for positioning and formatting x and y labels and to draw arrows pointing towards these labels. Today I wrote a function that similarly formats the colorbar label. However, the behavior is erroneous if the function is called within a block of code or in a script executed on the command line. I defined a condensed version of the function here as mycolorbar().

If I run the following in a script from the command line, or if I paste everything into a single code block in the Jupyter QtConsole, I get the figure shown below the code. In the QtConsole this occurs regardless of whether I've called %matplotlib

import matplotlib.pyplot as plt
import numpy as np

def mycolorbar(ax,cbar):
fig = ax.get_figure()
cax = cbar.ax
inv = ax.transAxes.inverted()
R = fig.canvas.get_renderer()
caxY = cax.yaxis
ylab = caxY.get_label()
ticklabelbbox = inv.transform( caxY.get_ticklabel_extents(R)[1].get_points() )
ylab.set_verticalalignment('center')
ylab.set_horizontalalignment('center')
ylab.set_rotation(0)
xpos, ypos = np.max(ticklabelbbox[:,0]), (3/4)
caxY.set_label_coords( xpos , ypos , transform = ax.transAxes )

x,y,z = [np.random.rand(1000) for i in range(3)]

fig = plt.figure(facecolor='w')
ax = fig.add_axes([.1,.1,.8,.8])
plt.tricontourf(x,y,z)
plt.xlabel('xlab')
plt.ylabel('ylab')
cbar = plt.colorbar(label='clab')
mycolorbar( ax, cbar)
plt.show()

Observe how far out to the right the colorbar label are. This is "incorrect".

Now, when working interactively in the QtConsole, if I run all of the above code _except_ the last line, let the figure window render, then execute that last line mycolorbar( ax, cbar) on its own, I get the "correct" position for the colorbar label.

I'm asking anyone to debug my code. Just trying to bring a potential issue to light. Thank you.