plotly
Customizing the order of legends in plotly
You can use traceorder key for legend: Determines the order at which the legend items are displayed. If “normal”, the items are displayed top-to-bottom in the same order as the input data. If “reversed”, the items are displayed in the opposite order as “normal”. If “grouped”, the items are displayed in groups (when a trace … Read more
How to save plotly express plot into a html or static image file?
Updated answer: With newer versions of plotly, static Image export in Python is a breeze. Just make sure to install kaleido using: pip install -U kaleido or, for Anaconda: conda install -c conda-forge python-kaleido And then run fig.write_image(“yourfile.png”) Filetypes such as .jpeg and .pdf are also available options. Producing an individual html file is still … Read more
Embedding a Plotly chart in a Django template
Instead of writing the html to a file you can have plotly return the html part of the graph as a string. For example, using a class based TemplateView: EDIT: Update for using recent (as of 2021/08) versions of plotly. The template does not need any changes. import plotly.graph_objects as go class Graph(TemplateView): template_name=”graph.html” def … Read more
plotly sankey graph data formatting
the structure is clearly a pandas dataframe constructor format create a dataframe from it, plus the key series of the nodes from this it’s simple to construct a Sankey plot from it import pandas as pd import numpy as np import plotly.graph_objects as go links = [ {‘source’: ‘start’, ‘target’: ‘A’, ‘value’: 2}, {‘source’: ‘A’, … Read more
Is it possible to create a subplot with Plotly Express?
Yes, you can build subplots using plotly express. Either 1. directly through the arguments facet_row and facet_colums (in which case we often talk about facet plots, but they’re the same thing), or 2. indirectly through “stealing” elements from figures built with plotly express and using them in a standard make_subplots() setup with fig.add_traces() Method 1: … Read more
Python package to plot two heatmaps in one (split each square into two triangles)
plt.tripcolor colors a mesh of triangles similar to how plt.pcolormesh colors a rectangular mesh. Also similar to pcolormesh, care has to be taken that there is one row and one column of vertices less than there are triangles. Furthermore, the arrays need to be made 1D (np.ravel). All this renumbering to 1D can be a … Read more
Plotly: How to set node positions in a Sankey Diagram?
In go.Sankey() set arrangement=”snap” and adjust x and y positions in x=<list> and y=<list>. The following setup will place your nodes as requested. Plot: Please note that the y-values are not explicitly set in this example. As soon as there are more than one node for a common x-value, the y-values will be adjusted automatically … Read more