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

Saving shrinked version of color bar in heatmap leads to saving the unshrinked version [BUG] #4605

Closed
shayandavoodii opened this issue Dec 19, 2022 · 2 comments
Labels

Comments

@shayandavoodii
Copy link

shayandavoodii commented Dec 19, 2022

Details

Plotting a heatmap plot:

using DataFrames, Plots, Statistics, RDatasets

iris_df = dataset("datasets", "iris")
cor_mat = cor(Matrix(iris_df[:, 1:4]), dims=1)
col_names = names(iris_df)[1:end-1]
heatmap(
  col_names, col_names, cor_mat,
  rightmargin=20Plots.mm,
  leftmargin=10Plots.mm,
  aspect_ratio=:equal,
  size=(700, 700),
  title="Correlation heatmap between 4 features of the Iris dataset",
  xlabel="Features", ylabel="Features",
  colorbar_title="Correlation",
  color=:bluesreds,
  framestyle=:box,
  titlefont=font(12)
)
plot!(dpi=200)
savefig("cor.png")

Leads to
image

Then I tried to shrink the color bar length to fit the plot. So first, I began with changing the backend to pyplot and pythonplot and moving the dpi into the heatmap function:

pyplot()

heatmap(
  col_names, col_names, cor_mat,
  rightmargin=20Plots.mm,
  leftmargin=10Plots.mm,
  aspect_ratio=:equal,
  size=(700, 700),
  title="Correlation heatmap between 4 features of the Iris dataset",
  xlabel="Features", ylabel="Features",
  colorbar_title="Correlation",
  color=:bluesreds,
  framestyle=:box,
  titlefont=font(12),
  dpi=300
)

savefig("cor.png")

And in the VSCode plot pane, it shows:
image

But the result of savefig is the same as unshrinked version!! :D

Backends

This bug occurs on ( insert x below )

Backend yes no untested
gr (default)
pythonplot x
plotlyjs
pgfplotsx
unicodeplots
inspectdr
gaston
pyplot x

Versions

Plots.jl version: 1.37.2
Backend version (]st -m <backend(s)>):

(@v1.8) pkg> st -m PyPlot PythonPlot GR
Status `C:\Users\Shayan\.julia\environments\v1.8\Manifest.toml`
  [28b8d3ca] GR v0.71.1
  [d330b81b] PyPlot v2.11.0
  [274fc56d] PythonPlot v1.0.0

Output of versioninfo():

julia> versioninfo()
Julia Version 1.8.3
Commit 0434deb161 (2022-11-14 20:14 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 8 × Intel(R) Core(TM) i7-4800MQ CPU @ 2.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, haswell)
  Threads: 8 on 8 virtual cores
Environment:
  JULIA_CONDAPKG_BACKEND = Null
  JULIA_PYTHONCALL_EXE = C:\Users\Shayan\AppData\Local\Programs\Python\Python310\python.exe
  JULIA_EDITOR = code
@shayandavoodii shayandavoodii changed the title Saving shrinked version of color bar in heatmap leads to saving the unsshrinked version [BUG] Saving shrinked version of color bar in heatmap leads to saving the unshrinked version [BUG] Dec 19, 2022
@BioTurboNick
Copy link
Member

I think the colorbar always takes up as much height as it can. You could achieve what you want by just reducing the height of the plot.

But for this issue specifically, I suppose the layout code is different for some reason depending on the display device? Not sure if that's a backend issue or a Plots issue.

@shayandavoodii
Copy link
Author

I think the colorbar always takes up as much height as it can. You could achieve what you want by just reducing the height of the plot.

But for this issue specifically, I suppose the layout code is different for some reason depending on the display device? Not sure if that's a backend issue or a Plots issue.

Hi, thanks.
Issue solved by setting lims=(0,4) in the heatmap function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants