-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH add plotly backend to plot_murphy_diagram (#140)
- Loading branch information
1 parent
39bfe14
commit c03d022
Showing
5 changed files
with
163 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import sys | ||
|
||
import matplotlib as mpl | ||
|
||
|
||
def get_plotly_color(i): | ||
try: | ||
sys.modules["plotly"] | ||
# Sometimes, those turn out to be the same as matplotlib default. | ||
# colors = plotly.colors.DEFAULT_PLOTLY_COLORS | ||
# Those are the plotly color default color palette in hex. | ||
import plotly.express as px | ||
|
||
colors = px.colors.qualitative.Plotly | ||
return colors[i % len(colors)] | ||
except KeyError: | ||
return False | ||
|
||
|
||
def get_xlabel(ax): | ||
if isinstance(ax, mpl.axes.Axes): | ||
return ax.get_xlabel() | ||
else: | ||
# ax = plotly figure | ||
return ax.layout.xaxis.title.text | ||
|
||
|
||
def get_ylabel(ax): | ||
if isinstance(ax, mpl.axes.Axes): | ||
return ax.get_ylabel() | ||
else: | ||
# ax = plotly figure | ||
return ax.layout.yaxis.title.text | ||
|
||
|
||
def get_title(ax): | ||
if isinstance(ax, mpl.axes.Axes): | ||
return ax.get_title() | ||
else: | ||
# ax = plotly figure | ||
return ax.layout.title.text | ||
|
||
|
||
def get_legend_list(ax): | ||
if isinstance(ax, mpl.axes.Axes): | ||
return [t.get_text() for t in ax.get_legend().get_texts()] | ||
else: | ||
# ax = plotly figure | ||
return [d.name for d in ax.data if d.showlegend is None or d.showlegend] | ||
|
||
|
||
def is_plotly_figure(x): | ||
"""Return True if the x is a plotly figure.""" | ||
try: | ||
plotly = sys.modules["plotly"] | ||
except KeyError: | ||
return False | ||
return isinstance(x, plotly.graph_objects.Figure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.