- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 784 Articles for Data Visualization
986 Views
To make two markers share the same label in the legend using Matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Plot x and y(as a sin(x) and cos(x)), using plot() method.Place legend with location=1.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(-5, 5, 100) plt.plot(x, np.sin(x), ls="dotted", label='y=f(x)') plt.plot(x, np.cos(x), ls="-", label='y=f(x)') plt.legend(loc=1) plt.show()OutputIt is not recommended to make two markers share the same label ... Read More
836 Views
To manipulate on horizontal space in Matplotlib subplots, we can use wspace=1 in subplots_adjust() method without tight plot layout.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots with 4 indices.To adjust the vertical space, we can use wspace=1.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 2 * np.pi, 400) y = np.sin(x ** 2) fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2) fig.subplots_adjust(wspace=1) ... Read More
652 Views
o get the list of font family in Matplotlib, we can take the following steps −Iterate fonts manager ttflist and print the names.Iterate fonts manager afmlist and print the names.Exampleimport matplotlib.font_manager as fm for f in fm.fontManager.ttflist: print(f.name) for f in fm.fontManager.afmlist: print(f.name)OutputSTIXNonUnicode STIXGeneral STIXSizeFiveSym cmr10 ... ... ... Nimbus Sans L Bitstream Charter Nimbus Sans L Nimbus Sans L
496 Views
To pass parameters to on_key in fig.canvas.mpl_connect('key_press_event', on_key), we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a figure and a set of subplots.Set x and y scale of the axes.Bind the function to the event.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() ax.set_xlim(0, 10) ax.set_ylim(0, 10) def onkey(event): if event.key.isalpha(): if event.xdata is not None and event.ydata is not None: ax.plot(event.xdata, event.ydata, 'bo-') ... Read More
355 Views
To customizing annotation with seaborn's face grid, we can take following steps −Set the figure size and adjust the padding between and around the subplots.Create a data frame with col1 and col2 columns.Multi-plot grid for plotting conditional relationships.Apply a plotting function to each facet's subset of the data.Set the title of each grids.To display the figure, use show() method.Exampleimport pandas as pd import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True df = pd.DataFrame({'col1': [3, 7, 8, 1], 'col2': ["three", "seven", "one", "zero"]}) g = sns.FacetGrid(data=df, col='col2', height=3.5) g.map(plt.hist, 'col1', ... Read More
3K+ Views
To manipulate on vertical space in Matplotlib subplots, we can use hspace=1 in subplots_adjust() method without tight plot layout.StepsSet the figure size and adjust the padding between and around the subplots.Create x and y data points using numpy.Create a figure and a set of subplots with 4 indices.To adjust the vertical space, we can use hspace=1.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True x = np.linspace(0, 2 * np.pi, 400) y = np.sin(x ** 2) fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(nrows=2, ncols=2) fig.subplots_adjust(hspace=1) ... Read More
840 Views
To convert data values into color information for Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Get a colormap instance, defaulting to rc values if *name* is None.Create random values that could be converted into color information.Create random data points, x and y.Use scatter() method to plot x and y.To display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plasma = plt.get_cmap('GnBu_r') values = np.random.rand(100) x = np.random.rand(len(values)) y = np.random.rand(len(values)) sc = plt.scatter(x, ... Read More
1K+ Views
To get interactive plots, we need to activate the figure. Using plt.ioff() and plt.ion(), we can perform interactive actions with a plot.Open Ipython shell and enter the following commands on the shell.ExampleIn [1]: %matplotlib auto Using matplotlib backend: GTK3Agg In [2]: import matplotlib.pyplot as In [3]: fig, ax = plt.subplots() # Diagram will pop up. Let’s interact. In [4]: ln, = ax.plot(range(5)) # Drawing a line In [5]: ln.set_color("orange") # Changing drawn line to orange In [6]: plt.ioff() # Stopped interaction In [7]: ln.set_color("red") # Since we have stopped the interaction ... Read More
2K+ Views
To display different images with actual size in a Matplotlib subplot, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Read two images using imread() method (im1 and im2)Create a figure and a set of subplots.Turn off axes for both the subplots.Use imshow() method to display im1 and im2 data.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True im1 = plt.imread("bird.jpg") im2 = plt.imread("opencv-logo.png") fig, ax = plt.subplots(nrows=1, ncols=2) ax[1].axis('off') ax[1].imshow(im1, cmap='gray') ax[0].axis('off') ax[0].imshow(im2, cmap='gray') plt.show()OutputRead More
695 Views
To male bar plots automatically cycle across different colors, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Set automatic cycler for different colors.Make a Pandas dataframe to plot the bars.Use plot() method with kind="bar" to plot the bars.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import pandas as pd plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True plt.rc('axes', prop_cycle=(plt.cycler('color', ['r', 'g', 'b', 'y']))) df = pd.DataFrame(dict(name=["John", "Jacks", "James"], age=[23, 20, 26], marks=[88, 90, 76], salary=[90, 89, 98])) df.set_index('name').plot(kind='bar') plt.show()OutputRead More