-
Notifications
You must be signed in to change notification settings - Fork 3
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
Assign different portions of a single colormap to different sub-colormaps #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ end | |
|
||
export plot_fslice, plot_velocity, plot_simage, plot_sdata, wiggle_plot | ||
export colorschemes | ||
export create_multi_color_map | ||
|
||
""" | ||
_plot_with_units(image, spacing; perc=95, cmap=:cet_CET_L1, | ||
|
@@ -286,4 +287,43 @@ function wiggle_plot(data::Array{Td, 2}, xrec=nothing, time_axis=nothing; | |
ax.set_ylabel("Time") | ||
end | ||
|
||
""" | ||
create_multi_color_map(intervals, cmap_types) | ||
|
||
Create a single colormap that assigns different portions of it to different sub-colormaps. | ||
|
||
# Arguments | ||
- `intervals::Vector{Tuple{T, T}}`: intervals of values where each interval will be assigned to a different colormap | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's not super practical especially considering it plots with perc. Working with actual portion in % or something would be more user friendly. |
||
- `cmap_types::Vector{ColorMap}`: colormaps for each interval | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just |
||
- `out_of_interval_color`: (Optional) the color assigned to values that live outside of all the intervals, default is black [0.,0.,0.,1.] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Someting like taht is usually just called padding |
||
|
||
# Example | ||
create_multi_color_map([(1,2),(3,4),(5,6)], [matplotlib.cm.YlGn,matplotlib.cm.Purples,matplotlib.cm.Reds]) | ||
""" | ||
function create_multi_color_map(intervals::Vector{Tuple{T, T}}, cmap_types::Vector{ColorMap}; out_of_interval_color=[0.,0.,0.,1.]) where T | ||
|
||
@assert length(intervals) == length(cmap_types) "number of intervals and number of colormaps do not match" | ||
|
||
# ensure at least 100 points in each interval | ||
colorrange = intervals[1][1]:minimum([intervals[i][2]-intervals[i][1] for i = 1:length(intervals)])/1f2:intervals[end][2] | ||
|
||
# number of points in each colormap | ||
colorlength = [Int.(round.((intervals[i][2]-intervals[i][1])./(colorrange[2]-colorrange[1]))) for i = 1:length(intervals)] | ||
|
||
# create each colormap | ||
cmap_sections = [cmap_types[i](range(0f0, stop=1f0, length=colorlength[i])) for i = 1:length(cmap_types)] | ||
|
||
# fill in out-of-interval by out_of_interval_color | ||
between_interval_sections = [reshape(repeat(out_of_interval_color, inner=Int(round((intervals[i][1]-intervals[i-1][2])/(colorrange[2]-colorrange[1])))), :, 4) for i = 2:length(intervals)] | ||
|
||
# concatenate all the sections to get the entire colormap | ||
total_sections = vcat(cmap_sections[1], vcat([vcat(between_interval_sections[i], cmap_sections[i+1]) for i = 1:length(cmap_sections)-1]...)) | ||
|
||
# construct the colormaps | ||
cmaps = matplotlib.colors.ListedColormap(total_sections) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks bit overly intricated but that's fine |
||
|
||
return cmaps | ||
|
||
end | ||
|
||
end # module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate an actual illustrative example like all the other ones that use proper images/shot records/.... because this doesn't really show anything.