Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow 2d coordinates for heatmap plots in PyPlot backend #4298

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

johnomotani
Copy link

Allows plotting on a non-rectangular grid, at least with PyPlot backend. For example:

using Plots
pyplot()

nx = 10
ny = 11

x = zeros(ny, nx)
y = zeros(ny, nx)

for i  1:nx, j  1:ny
    x[j,i] = i
    y[j,i] = 2.0 + j + i
end

z = randn(ny,nx)

heatmap(x,y,z)

savefig("test.png")

produces
test

Currently 'Draft' because:

  • _heatmap_edges() is fudged for 2d x and y. PyPlot can handle the cell-centre/cell-edge conversion automatically so the _heatmap_edges() functionality is not needed for the case I was trying to get working. It would be nicer to be more general, but the logic is a bit more complicated (I guess an extra argument would need to be passed to say which dimension needs to be converted from centres to edges?) - is it worth doing and does anyone have opinions/suggestions on the best way?
  • I guess a test would be good? I would be very grateful for a pointer on where the test should go and if there is something similar I could copy to start from.
  • What to do about other backends? I tried running the same test case with GR and got an error that seemed to happen due to z being transposed. I got lost trying to look for where a special-case for 2d x and y would be needed though... Should only backends where 2d x and y are known to work be supported? If so where would be a good place to throw an error for unsupported backends?

Maybe an expert can see a better way to implement this and would find it easier to start from scratch, in which case please consider this just a feature request!

Allows plotting on a non-square grid for backends that support it.
@codecov
Copy link

codecov bot commented Aug 3, 2022

Codecov Report

Merging #4298 (3133ee8) into master (6d537c6) will decrease coverage by 0.18%.
The diff coverage is 11.11%.

@@            Coverage Diff             @@
##           master    #4298      +/-   ##
==========================================
- Coverage   79.92%   79.74%   -0.19%     
==========================================
  Files          29       29              
  Lines        6969     6986      +17     
==========================================
+ Hits         5570     5571       +1     
- Misses       1399     1415      +16     
Impacted Files Coverage Δ
src/utils.jl 72.87% <0.00%> (-1.80%) ⬇️
src/axes.jl 86.27% <66.66%> (-0.16%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@t-bltg t-bltg added the PyPlot label Aug 4, 2022
johnomotani added a commit to mabarnes/moment_kinetics that referenced this pull request Aug 10, 2022
Also requires updated version of Plots.jl (to be added later if/when
JuliaPlots/Plots.jl#4298 is merged).
johnomotani added a commit to mabarnes/moment_kinetics that referenced this pull request Sep 13, 2022
Also requires updated version of Plots.jl (to be added later if/when
JuliaPlots/Plots.jl#4298 is merged).
johnomotani added a commit to mabarnes/moment_kinetics that referenced this pull request Sep 13, 2022
Making animations directly with PyPlot.jl and matplotlib is not as neat,
and the output is not consistent with Plots.jl, but it works without
needing the update to Plots.jl in
JuliaPlots/Plots.jl#4298
johnomotani added a commit to mabarnes/moment_kinetics that referenced this pull request Sep 13, 2022
Also requires updated version of Plots.jl (to be added later if/when
JuliaPlots/Plots.jl#4298 is merged).
johnomotani added a commit to mabarnes/moment_kinetics that referenced this pull request Sep 13, 2022
Making animations directly with PyPlot.jl and matplotlib is not as neat,
and the output is not consistent with Plots.jl, but it works without
needing the update to Plots.jl in
JuliaPlots/Plots.jl#4298
@t-bltg t-bltg added the extension new behaviour label Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension new behaviour PyPlot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants