Code Monkey home page Code Monkey logo

Comments (4)

Witold1 avatar Witold1 commented on May 21, 2024

Hello @Jankowski-J - try matplotlib.pyplot.savefig method (documentation), it's a standard built-in method in matplotlib to save a figure class object. Example: stackoverflow question

Package is a purpose-based wrapper above matplotlib, so all logic and methods are inherited for respective objects.

from july.

Jankowski-J avatar Jankowski-J commented on May 21, 2024

I've tried what you have suggested, I've also looked into the properties available in object returned by july.heatmap() method. I can't seem to find any relevant method to save the image.

The heatmap variable is of type AxesSubplot and I don't know how to save that to file.

Below is a snippet of my code:

import numpy as np
from plotly_calplot import calplot

import matplotlib.pyplot as plt

import july
from july.utils import date_range


def main():
    dates = date_range("2020-01-01", "2020-12-31")
    data = np.random.randint(0, 14, len(dates))

    heatmap = july.heatmap(dates, data, title='Github Activity', cmap="github")

    # both of these lines throw an exception
    heatmap.save_fig("saved_hm.png")
    plt.save_fig("test_heatmap.png")


if __name__ == "__main__":
    main()

from july.

Witold1 avatar Witold1 commented on May 21, 2024

@Jankowski-J - try plt.savefig("test_heatmap.png") instead of plt.save_fig("test_heatmap.png"), you have a typo underscore (..._...) in a name of a method (see documentation). This method will take the current figure (~the last active figure) and save it

heatmap = july.heatmap(dates, data, title='Github Activity', cmap="github")
plt.savefig("test_heatmap.png")

Alternatively, try the next snippet because heatmap object is <class 'matplotlib.axes._subplots.AxesSubplot'>. Matplotlib allows to save figure objects not axes objects (see example stackoverflow question). It also allows to save the selected figure

fig, ax = plt.subplots(1, 1, figsize=(12, 10)) # create figure object and one axes objects
heatmap = july.heatmap(dates, data, title='Github Activity', cmap="github", ax=ax) # plot a chart to ax subplot
fig.tight_layout() # auto adjust the padding between and around subplots.
fig.savefig("saved_hm.png") # save figure

Also, check the dpi and facecolor params to increase the image quality and change the background color (from transparent to needed color code).

Also, there is already a pull request to save it inside the package interface - #27

from july.

Jankowski-J avatar Jankowski-J commented on May 21, 2024

Thank you for your explanation @Witold1 , now I can save the output.
I have no further questions, so I will close the issue soon.

from july.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.