Title: Type error in matplotlib renderer when saving pcolormesh figure
Tags: python-3.x,matplotlib,conda

Question: I've recently changed one of my plotting scripts to use pcolormesh instead of contourf. It's part of a script that loops over several netCDF datasets to create a couple of maps at different timesteps and, in the problematic part, cross-sections of some variables at a specific location over time. The code line used to be:
im = ax.contourf(X,Y,np.transpose(data),*args,**kwargs)

where X (time, converted to float64 seconds) and Y (height, also float64) are a meshgrid and data is the corresponding slice of the netcdf dataset (float32). I replaced it with
im = ax.pcolormesh(X,Y,np.transpose(data),shading='gouraud',*args,**kwargs)

as it happened that the plot style works better for the data. The kwargs are a colorbar and the colorbar limits, nothing out of the ordinary.
It worked fine on my small test case that I had on my local (Windows) machine using spyder, however when I try to use it on the (Linux) Server from the command line, it suddenly gives me the following error message when I'm trying to save the plot:
Traceback (most recent call last):
  File "(redacted)/main.py", line 37, in <module>
    dataset.make_plots()
  File "(redacted)/plotDataset.py", line 75, in make_plots
    self._crossecPlot(data, variable, crossec)
  File "(redacted)/plotDataset.py", line 196, in _crossecPlot
    plt.savefig(self.settings['output_path']+'/'+filename+'.png', bbox_inches='tight')
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/pyplot.py", line 1023, in savefig
    res = fig.savefig(*args, **kwargs)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/figure.py", line 3343, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/backends/backend_qtagg.py", line 75, in print_figure
    super().print_figure(*args, **kwargs)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2366, in print_figure
    result = print_method(
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2232, in <lambda>
    print_method = functools.wraps(meth)(lambda *args, **kwargs: meth(
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py", line 509, in print_png
    self._print_pil(filename_or_obj, "png", pil_kwargs, metadata)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py", line 457, in _print_pil
    FigureCanvasAgg.draw(self)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py", line 400, in draw
    self.figure.draw(self.renderer)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/artist.py", line 95, in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/figure.py", line 3140, in draw
    mimage._draw_list_compositing_images(
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/axes/_base.py", line 3064, in draw
    mimage._draw_list_compositing_images(
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/image.py", line 131, in _draw_list_compositing_images
    a.draw(renderer)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/artist.py", line 72, in draw_wrapper
    return draw(artist, renderer)
  File "(redacted)/miniconda3/lib/python3.10/site-packages/matplotlib/collections.py", line 2095, in draw
    renderer.draw_gouraud_triangles(
TypeError: Cannot cast array data from dtype('float128') to dtype('float64') according to the rule 'safe'

I've already tried using the default (nearest) shading type instead of Gouraud triangles, which gave me the same error except that it's in renderer.draw_quad_mesh, and I've used the shared anaconda installation before installing miniconda with the hope that it was something that got fixed in an update.
What is suprising to me, when i use im = ax.pcolormesh(lons,lats,values,transform=ccrs.PlateCarree(),*args, **kwargs) in a different plot type (which uses a different slice of the same data and cartopy), the error doesn't occur. All in all though, I have no idea where the float128 type is coming from, and why it wouldn't convert to a float64 (since it's only for plotting, i would think that the lost precision shouldn't be much of an issue).

Answer: It seems to be as Jody Klomak said - if I explicitly cast X, Y, and the data to float64 by adding .astype('float64'), it works. I still didn't figure out why it happened in the first place, but I'm happy that it works now.