logo
down
shadow

Using Python libraries to plot two horizontal bar charts sharing same y axis


Using Python libraries to plot two horizontal bar charts sharing same y axis

By : Cust0dian
Date : November 17 2020, 04:28 AM
To fix this issue Generally speaking, if the two variables you're displaying are in different units or have different ranges, you'll want to use two subplots with shared y-axes for this. This is similar to what the answer by @regdoug does, but it's best to explicitly share the y-axis to ensure that your data stays aligned (e.g. try zooming/panning with this example).
For example:
code :
import matplotlib.pyplot as plt

y = range(20)
x1 = range(20)
x2 = range(0, 200, 10)

fig, axes = plt.subplots(ncols=2, sharey=True)
axes[0].barh(y, x1, align='center', color='gray')
axes[1].barh(y, x2, align='center', color='gray')
axes[0].invert_xaxis()
plt.show()
import numpy as np
import matplotlib.pyplot as plt

# Data
states = ["AK", "TX", "CA", "MT", "NM", "AZ", "NV", "CO", "OR", "WY", "MI",
          "MN", "UT", "ID", "KS", "NE", "SD", "WA", "ND", "OK"]
staff = np.array([20, 30, 40, 10, 15, 35, 18, 25, 22, 7, 12, 22, 3, 4, 5, 8,
                  14, 28, 24, 32])
sales = staff * (20 + 10 * np.random.random(staff.size))

# Sort by number of sales staff
idx = staff.argsort()
states, staff, sales = [np.take(x, idx) for x in [states, staff, sales]]

y = np.arange(sales.size)

fig, axes = plt.subplots(ncols=2, sharey=True)
axes[0].barh(y, staff, align='center', color='gray', zorder=10)
axes[0].set(title='Number of sales staff')
axes[1].barh(y, sales, align='center', color='gray', zorder=10)
axes[1].set(title='Sales (x $1000)')

axes[0].invert_xaxis()
axes[0].set(yticks=y, yticklabels=states)
axes[0].yaxis.tick_right()

for ax in axes.flat:
    ax.margins(0.03)
    ax.grid(True)

fig.tight_layout()
fig.subplots_adjust(wspace=0.09)
plt.show()
axes[0].set(yticks=y, yticklabels=[])
for yloc, state in zip(y, states):
    axes[0].annotate(state, (0.5, yloc), xycoords=('figure fraction', 'data'),
                     ha='center', va='center')


Share : facebook icon twitter icon
Is it possible in highcharts to have 2 charts, sharing the same x-axis, but next to one another?

Is it possible in highcharts to have 2 charts, sharing the same x-axis, but next to one another?


By : Ahsan Chaudhary
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The same properties you can use for xAxis (top, left, width, height), see: http://jsfiddle.net/F3pts/7/
code :
xAxis: [{
    gridLineWidth: 1,
    width :150
}, {
    offset: 0,
    gridLineWidth: 1,
    width :150,
    left: 230
}],
Align a double line chart and a bar plot on the x axis when both charts have the same X axis. ggplot2

Align a double line chart and a bar plot on the x axis when both charts have the same X axis. ggplot2


By : emmanouil
Date : March 29 2020, 07:55 AM
wish of those help This will align the x-axis and fix the layout. However, there is still spacing between the figures.
code :
## Specify the xlimits
xlims <- as.Date(c("2015-07-21", "2015-08-06"))

## low_bar as you had it, except the ylimits are adjusted for labels and xlims added
low_bar <- ggplot(data = GFS_low_changes, aes(x= Date, y = temp_deltalow)) + 
  geom_bar(colour= "black", fill= ifelse(temp_deltalow>0,"red","blue"), stat= "identity", position = "identity") +
  geom_text(aes(label= paste(temp_deltalow, "°F"),hjust= 0.4, vjust= ifelse(temp_deltalow>0,-0.5,1)), size= 5) +
  ylim(-4, 5) +
  xlim(xlims)

## low_line, legend is changed and xlims is added
low_line <- ggplot(GFS_low_changes, aes(Date)) +
  geom_line(aes(y= Mean_temp12z, colour= "Mean_temp12z" )) +
  geom_line(aes(y= Mean_temp0z, colour= "Mean_temp0z"))+
  geom_point(aes(y= Mean_temp12z))+
  geom_point(aes(y= Mean_temp0z))+
  theme(legend.title= element_text(colour="black", size=12))+
  scale_color_discrete(name="GFS Models")+ labs(y= "Temperature °F") +
  theme(legend.position = c(0.9,0.8)) +
  xlim(xlims)

## Construct the layout, 2 rows one column
grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 1)))
print(low_bar, vp = viewport(layout.pos.row = 2, layout.pos.col=1))
print(low_line, vp = viewport(layout.pos.row = 1, layout.pos.col=1))
Multiple charts sharing the same x-axis in Google Charts

Multiple charts sharing the same x-axis in Google Charts


By : Mayur Gupta
Date : March 29 2020, 07:55 AM
hope this fix your issue We are working on object oriented solution for charts and we are thinking to make it open source. You can have a look and you can use chart skelton to fulfill your needs. Here is the link (click on the first chart) http://grafitome.github.io/advanced-charts.html#
sharing X axis between d3 charts in angular

sharing X axis between d3 charts in angular


By : Gorav Singh
Date : March 29 2020, 07:55 AM
may help you . I solved this issue by creating a separate array of dates that all of the charts use for their x domain.
Every time a new item is added to the chart ng-repeat, their dates are also pushed into another array that is sorted by date.
code :
$scope.$watch('at', (function (newVal, oldVal) {
            this.xDomain = $scope.xdomain;
            this.yDomain = (typeof $scope.ydomain === 'function' ? $scope.ydomain : yDomainCommand);
            // Redraw the graph after new data loads.
            drawAxes();
            plotData(this.data);
            append($scope.lines || [], this.data);
            $compile($element)($scope);
        }).bind(this));
scope: {
            x: '@',
            y: '@',
            height: '=',
            width: '=',
            margin: '=',
            chartData: '=',
            at: '=parentData', // used to access outside scope
Holoviews charts sharing axis when combined and outputted

Holoviews charts sharing axis when combined and outputted


By : Manoj Srivastava
Date : March 29 2020, 07:55 AM
should help you out This happens when the y-axes have the same name.
You need to use option axiswise=True if you want every plot to get its own independent x-axis and y-axis.
code :
# import libraries etc.
import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')

# create some sample data
df1 = pd.DataFrame({
    'x': np.random.rand(10), 
    'y': np.random.rand(10),
})

df2 = pd.DataFrame({
    'x': np.random.rand(10) * 10, 
    'y': np.random.rand(10) * 10,
})

# set axiswise=True so that every plot gets its own independent x- and y-axis    
plot1 = hv.Scatter(df1).opts(axiswise=True)
plot2 = hv.Scatter(df2).opts(axiswise=True)

plot1 + plot2
plot1 = hv.Scatter(df1)
plot2 = hv.Scatter(df2)

(plot1 + plot2).opts(opts.Scatter(axiswise=True))
Related Posts Related Posts :
  • Return new instance of subclass when using methods inherited from parent class in Python
  • Which function in django.contrib.auth creates the default model permissions?
  • Formatting text in tabular form with Python
  • How to determine the first day of a month in Python
  • Error while converting date to timestamp in python
  • Python string iterations
  • Is there any file number limitation when you select multiple files with wxFileDialog?
  • Errors with Matplotlib when making an executable with Py2exe (Python)
  • Django Haystack - Indexing single field
  • Go Pro Hero 3 - Streaming video over wifi
  • Appending a column in .csv with Python/Pandas
  • How to change my result directory in Robot framework using RIDE?
  • problem with using pandas to manipulate a big text file in python
  • python-magic module' object has no attribute 'open'
  • Where goes wrong for this High Pass Filter in Python?
  • Why inserting keys in order into a python dict is faster than doint it unordered
  • flann index saving in python
  • Create new instance of list or dictionary without class
  • How can I easily convert FORTRAN code to Python code (real code, not wrappers)
  • Address of lambda function in python
  • Python adding space between characters in string. Most efficient way
  • python http server, multiple simultaneous requests
  • Disguising username & password on distributed python scripts
  • Post GraphQL mutation with Python Requests
  • Why doesnt pandas create an excel file?
  • Rolling comparison between a value and a past window, with percentile/quantile
  • How to avoid repetitive code when defining a new type in python with signature verification
  • How to configure uWSGI in order to debug with pdb (--honour-stdin configuration issue)
  • In Python, how do you execute objects that are functions from a list?
  • Python- Variable Won't Subtract?
  • Processing Power In Python
  • Python 2.7.2 - Cannot import name _random or random from sys
  • Why doesn't the Python sorted function take keyword order instead of reverse?
  • Make a function redirect to other functions depending on a variable
  • get_absolute_url in django-categories
  • Monitoring non-Celery background task with New Relic in Python
  • Feature selection with LinearSVC
  • LSTM - Predicting the same constant values after a while
  • Test the length of elements in a list
  • Django: render radiobutton with 3 columns, cost column must change according to size & quantity selected
  • Python class attributes vs global variable
  • sys.stdout.writelines("hello") and sys.stdout.write("hello")
  • is ndarray faster than recarray access?
  • Python - search through directory trees, rename certain files
  • GAE: How to build a query where a string begins with a value
  • TypeError: __init__() takes at least 2 arguments (1 given)
  • Overriding and customizing "django.contrib.auth.views.login"
  • Django : Redirect to a particular page after login
  • Python search and copy files in directory
  • pretty printing numpy ndarrays using unicode characters
  • Frequent pattern mining in Python
  • How can I make a set of functions that can be used synchronously as well as asynchronously?
  • Convert one dice roll to two dice roll
  • count occourrence in a list
  • Writing an If condition to filter out the first word
  • to read file and compare column in python
  • Install python-numpy in the Virtualenv environment
  • `.select_by_visible_text()` is failed to select element?
  • Unable to send data multiple requests in a single connection — socket error
  • Pandas HDFStore unload dataframe from memory
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org