Showing posts with label Legend. Show all posts
Showing posts with label Legend. Show all posts

Interactive figure with several 1D plot and one hovertools using Python and Bokeh


The result is:

Interactive figure with several 1D plot and one hovertools using Python and Bokeh

This code how to generate interactive figure with several 1D plot, one hovertools and togglable legend using Python and Bokeh. This is a continuing post of last one.

Interactive figure with interactive legend using Python, matplotlib.pyplot and mpld3


The result (static image) is:

Interactive figure with interactive legend using Python, matplotlib.pyplot and mpld3

This page shows how to plot data in interactive figure using python, matplotlib.pyplot and mpld3. A interactive legend is added to the figure.

Increase box size of the legend for barplot using Python and matplotlib.pyplot


The result is:

Increase box size of the legend for barplot using Python and matplotlib.pyplo

This page shows how to increase box size of the legend for barplots using Python and matplotlib.pyplot.

Plot three wave in one plot; PWM wave as example


The result is:


This page shows an example of a plot with three waves in one axes using offsets. The PWM wave is the objective.

Try all legend options in Python Matplotlib.pyplot


The default legend is:

Try all legend options - default result -

In this page, all legend options are tried.

Change the space between labels and lines of the legend in Python Matplotlib.pyplot


The result is:

Legend with changing padding between line and label using handletextpad option

This page how to change the space between the lines in legend and their labels.

Draw two legends in one figure using Python & Matplotlib.pyplot

In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
In [2]:
plt.figure(figsize=(4,3))

l1, = plt.plot([0,1],[1,0],label="l1")
l2, = plt.plot([0,1],[1.1,0],label="l2")
l3, = plt.plot([0,1],[1.2,0],label="l3")
h1 = [l1, l2, l3]
l4, = plt.plot([0,1],[0,1],"--",label="l4")
l5, = plt.plot([0,1],[0,1.1],"--",label="l5")
h2 = [l4, l5]

lab1 = [ h.get_label() for h in h1]
lab2 = [ h.get_label() for h in h2]

leg1 = plt.legend(h1,lab1, loc=1)
leg2 = plt.legend(h2,lab2, loc=4)

plt.gca().add_artist(leg1) # 最後の legend しか自動認識してくれない
plt.show()