PythonPlot: use imshow instead of pcolormesh for heatmaps

The following very hacky method appears to work with some caveats. Here’s a simplified example. First run this:

using Plots
import PythonPlot
pythonplot()
xs = range(-1, 1; length = 301)
ys = xs' 
Zs = @. cos(2π*xs)*sin(2π*ys)
ret_val = heatmap(xs, xs, Zs)

Wait for whatever Plots/Python is doing (julia will run the next command too soon otherwise). Then run this:

quad_mesh = ret_val.series_list[1][:serieshandle][1]
quad_mesh.set_rasterized(true)
ret_val.o.savefig("hm.pdf")

The output file is small (~32 kB) with only the heatmap rasterized. For your actual figure, you’ll have to try to hunt down which series is the one you need to extract. If it’s a heatmap, its serieshandle should be a matplotlib.collections.QuadMesh object

1 Like