8000 GitHub - fomightez/general_scripted_plotting: Scripts that make plots of generalized data.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fomightez/general_scripted_plotting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 

Repository files navigation

general_scripted_plotting

Scripts that plot 'generalized' data.

NOTE: This repository is just for scripts that have a very broad ability to make plots from 'generalized' data. I have many other scripts/Jupyter notebooks that are more nuanced, and hence not in this repo. A few of them are referenced below under the section Plotting scripts for specific purposes.

Descriptions of the scripts are below:

plot_panel_bar_plots_with_fit.py

A Python script to plot panels of bar graphs with optional curves fit to the data. It uses lists of lists of x & y data. Each set of x & y values is plotted to a subplot stacked upon each other subplot in the panel.

This script is my 'hacky' recasting of the histogram-generating (actually kernel density estimate curve plot-generating) code of joypy as a less automated, fully-customizable plotter of panels of bar graphs with curves fit to the data. (There might be some more current, more convenient versions than this among the resources I found listed here.) (A fancy, R-based version with vertical color gradient fill is illustrated in this vignette for devoutsvg.) (Also reminscent of ridgline plots done in R by ggridges, see here for an example. Vaguely also reminiscent of Seaborn's example of Overlapping densities (‘ridge plot’) (in fact title has been updated from 'Overlapping densities (‘joy plot’)'), and horizontal violin plots that show observations with a 'stick', but where one-sided and set up so can compare more than one. Also vaguely reminiscent of small-multipes charts. Also vaguely reminiscent of raincloud plots and beanplots (sina plots too?) illustrated and discussed here for R and beyond (see Raincloud Plots blog post here with updates here and with associated paper announced here) (and maybe made here in R a different(?) way); however, Davide Poggiali has successfully brought raincloud plot to Python/Seaborn so that it is available in several languages with a nice preprint (before the final paper in Wellcome Open Research; see linl above) and set of tutorials. (Stacked violin plots for seurat and scanpy remind me of what you'd need if correlating two category intersections, see here and links to scanpy function therein.) Note that sina plots and raincloud plots are more favored recently than perhaps violoin and box plot, see here for example.
Originally written to be part of a mini-pipeline, shepherds_read_starts_at_start_of_origins_thru_to_plotting.py, where I plot read starts at the start of origin promoters mined by plot_coverage_and_starts.py Thus, it was written in a manner to make the core function easily imported elsewhere so that the "data" hard coded in the example can be replaced by real data. Stylistically, it seems others have called this a 'panel of bar charts', see here and so my description/name is an effort to acknowledge that.

EXAMPLE OUTPUT THAT CAN BE MADE USING THIS SCRIPT: From shepherds script that imports this script

Two ways to use this script:

  • Edit it to contain your data.

    Edit the script directly via text editor. Assign your data and asign items like labels, colors, etc.

    Adjust the output image to be in the format you'd like. You may find .png best while developing because more easily directly viewed than svg; svg vector graphics format is more easily sized while maintaining quality and thus better suited for adapting for publication.

    Execute the edited script with:

    python plot_panel_bar_plots_with_fit.py
    

    The script can also simply be pasted into a cell in a Jupyter notebook and then executed as you would any code in a Jupyter notebook, i.e., type shift-enter or press play button. An example of an edited script pasted into a Jupyter notebook is included here in this repo; scroll all the way to the bottom to see ouput. Go here to see the example Jupyter notebook rendered nicely.

    The resulting image produced in that notebook is below:

    nine_notebook_example

  • (Recommended way ==>) Import the function into your own script with your data or your Jupyter notebook with your data.

    To do this, place the script plot_panel_bar_plots_with_fit.py into a directory with your code or place the script in your Jupyter environment on the same level where the notebook is located.

    Minimal code outline needed for that approach:

    import matplotlib
    from matplotlib import pyplot as plt
    import plot_panel_bar_plots_with_fit as plt_panel_bar #<--IMPORTS IF `plot_panel_bar_plots_with_fit.py` PLACED IN SAME DIRECTORY
    
    # assign your data
    
    # assign items like `labels`, `colors`, etc.
    
    ## MAKE PLOT by calling function ####
    
    fig, axes = plt_panel_bar.plot_data(
        data,
        #plus ettings for options, examples:
        labels=my_data_labels,
        colors=my_label_and_bar_colors, 
        bar_alphas=my_bar_alphas,
        label_alphas=my_label_alphas,
        shared_x_label=shared_x_label,
        shared_y_label=shared_y_label
        # Several other options are available for fully customizing output.
        )
    
    ### END OF PLOT MAKING #####
    
    
    # save or display returned plot in preferend format
    plt.savefig("plot.svg", orientation='landscape') # FOR VECTOR GRAPHICS; useful if merging into Adobe Illustrator.
    plt.savefig("plot.png") # may be best for development phase as viewable directly in more environments
    plt.show() # <=== Use that when placed in a Jupyter notebook
    

    See shepherds_read_starts_at_start_of_origins_thru_to_plotting.py for a full example implementing the import approach.

The resulting images produced are below in the two color options, respectively, with the second option selectable by editing the script shepherds_read_starts_at_start_of_origins_thru_to_plotting.py further to comment off the first option:

color_option_1 color_option_2

KNOWN ISSUES AND WORKAROUNDS:

I wanted to make plots where the x-axis was -70 through -1 and this script didn't seem to work and just output a tiny square as the plot. No clear error was reported although there was a warning:

UserWarning: Attempting to set identical left==right results
in singular transformations; automatically expanding.
left=0, right=0
  'left=%s, right=%s') % (left, right))

Turns out the warning and the "tiny square" plot are because the script tries to be smart (in a less than optimal way, for now) and set the x_lower_val to zero for sets less than 100 in size. However, if using strictly negative numbers for x-axis that causes a problem presently because the original implementation of handling that didn't take into account the entire range of x-axis values being negative values. The easy solution is just to supply x_lower_val in your plot_data() function call which overrides the script trying to set the values itself.

donut plots with subgroups from dataframes or data tables

This belongs under this topic but because I want to binderize the script and the demonstrations, I put it as a separate repo here.
Typical input example (red annotation is just for illustrating concepts):
data_input

Typical output examples:

typical 1


typical 2


typical 3

See here for more examples and information.

Plotting scripts for specific purposes

I have made many other scripts that plot data that aren't in this repository becauase they are for specific purposes or deal with specific forms of data.

Below are links to a few of these to aid in organization:

RELATED: I have a VPython-jupyter repo where I added the plotting package Seaborn.

Licensing

The scripts in this repository are licensed under MIT.

Related repositories of mine

General Python-based plotting scripts by others

Came across these and noted here since may be useful later and not in the usual packages I am familiary with:

About

Scripts that make plots of generalized data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0